How is this possible? Using MVC Razor, I marked my method with the [Authorize] attribute, which means that a user must be logged in to access the view right? But, sometimes I am getting the User.Identity.Name value as a null (so who’s logged in then?).
my method does not have any roles defined in the authorize attribute, its like so:
[Authorize]
public ActionResult PageToView(){
...
return View();
}
EDIT: I am using the default Role and Membership providers.
I had a similar issue before and it was because the HttpContext.Current.User was never being populated.
Please have a look at HttpContext.Current.User.Identity.Name returning null.
I hope that helps.