Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 436
shyama Avatar asked Nov 12 '14 08:11

shyama


1 Answers

Try this (MVC):

@{ var userName = System.Web.HttpContext.Current.User.Identity.Name; }
like image 53
Aidan Avatar answered Sep 29 '22 05:09

Aidan