How to get the current user in ASP.NET MVC

Serhat Ozgel picture Serhat Ozgel · Nov 4, 2008 · Viewed 365.4k times · Source

In a forms model, I used to get the current logged-in user by:

Page.CurrentUser

How do I get the current user inside a controller class in ASP.NET MVC?

Answer

Haacked picture Haacked · Nov 5, 2008

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.