shyama
shyama

Reputation: 331

getting current user name in razor

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

Answers (1)

Aidan
Aidan

Reputation: 5536

Try this (MVC):

@{ var userName = System.Web.HttpContext.Current.User.Identity.Name; }

Upvotes: 10

Related Questions