I一部のページでレンダリングサイドバーにViewComponentを使用します。私はいくつかのアクションのための現在のログインユーザーが必要です、どのようにViewComponentでユーザーを得ることができますか?もちろん、私はビューからInvokeAsyncメソッドにパラメータとして渡すことができますが、私はより良い方法を探しています。ViewComponentの現在のログインユーザーを取得する方法Asp.Netコア
public class SideBarViewComponent : ViewComponent
{
private readonly UserManager<User> _userManager;
public ProfileSideBarViewComponent(UserManager<User> userManager)
{
_userManager = userManager;
}
public async Task<IViewComponentResult> InvokeAsync()
{
//How access User
_userManager.GetUserId(User);
return View();
}
}