Reputation: 331
I want to get the current authenticated username in my razor view page, so I use
if (User.Identity.IsAuthenticated)
{
<p>Name is @User.Identity.Name</p>
}
but @User.Identity.Name always shows the id of the user.
Upvotes: 8
Views: 15122
Reputation: 5536
Try this (MVC):
@{ var userName = System.Web.HttpContext.Current.User.Identity.Name; }
Upvotes: 10