I use ASP.NET Identity 2.0 and MVC. I need to logged user\'s name,surname,email etc.. in view. How can get it? I can get just @User.Identity but there no my user class\'s pr
In case you using .NET Core app:
You can easily use the @inject
feature call for injecting both UserManager
and SignInManager
.
In your view add the following:
@inject SignInManager SignInManager
@inject UserManager UserManager
After the injection, you should be able to work with UserManager
and SignInManager
methods. For instance:
@if (SignInManager.IsSignedIn(User))
{
Hello @UserManager.GetUserName(User)
}
else
{
}
Pay attention for passing the
User
object when you need to reference the current logged in user.