In forms model, I used to get current logged in user by
Page.CurrentUser
How do I get current user inside a controller class in ASP.NET MVC?
In forms model, I used to get current logged in user by
Page.CurrentUser
How do I get current user inside a controller class in ASP.NET MVC?
I use:
Membership.GetUser().UserName
Not sure this will work in MVC but it's worth a shot :)
try HttpContext.Current.User
UPDATE (reading comment):
Public Shared Property Current() As System.Web.HttpContext
Member of System.Web.HttpContextSummary:
Gets or sets the System.Web.HttpContext object for the current HTTP request.Return Values:
The System.Web.HttpContext for the current HTTP request
.
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 realize this is really old, but I'm just getting started w/ MVC.Net, so I thought I'd stick my two cents in:
Request.IsAuthenticated tells you if the user is authenticated. Page.User.Identity gives you the identity of the logged-in user.
I found that 'User' works, ie. User.Identity.Name or User.IsInRole("Administrator")... Hope this helps although a bit late.
getting logged in username: System.Web.HttpContext.Current.User.Identity.Name