I have an ASP.Net MVC 5 project that I recently migrated from MVC 4. I'm using FormsAuthentication with HTTPS and anonymous authentication, and setting a cookie using this:
FormsAuthentication.RedirectFromLoginPage(Username, false)
Authentication works, but the issue I'm having is getting the current user's name in my C# code. I can get at it fine in my view,
User.Identity.GetUserName()
but I can't get at it in the controller. HttpContext.CurrentUser
doesn't exist, and this.User
in the controller is always null. I've also tried requesting the cookie, but it fails.
Will I have to set the Identity myself when they sign on? I may need user rolls, but I could always query the database to get them.
In short, how can I get the current user's username in my controller in MVC 5? Thanks