How to get the current user in ASP.NET MVC
If you need to get the user from within the controller, use the User
property of Controller. If you need it from the view, I would populate what you specifically need in the ViewData
, or you could just call User as I think it's a property of ViewPage
.
I found that User
works, that is, User.Identity.Name
or User.IsInRole("Administrator")
.