After constantly researching this problem, I finally found the answer with another SO question making my question look like a duplicate: MVC3 Windows Authentication overrides User.Identity
Below is the answer written by @Toby Jones (as editing his original question) that lead to a solution to my problem, but his answer is actually a combination of the two answers posted by @Erik Funkenbusch and @Darin Dimitrov. The answer is edited to correct some grammar and remove unnecessary information.
Option 1: override authorization request in Global.asax
The Application_AuthenticateRequest event should not be used because ( HttpContext.Current.User is null, even if Windows authentication is enabled), the user was not populated during Windows authentication, and therefore I can not use anything to get user information.
Application_AuthorizeRequest is the next in the chain and occurs after entering WindowsIdentity.
protected void Application_AuthorizeRequest(object sender, EventArgs e) { if (User.Identity.IsAuthenticated && Roles.Enabled) { Context.User = new CustomPrincipal((WindowsIdentity)User.Identity); } }
Option 2: Override the AuthorizeAttribute attribute
Here is the authorization attribute override
public class CAuthorize : AuthorizeAttribute { protected override bool AuthorizeCore(HttpContextBase httpContext) { bool authorized = base.AuthorizeCore(httpContext); if (!authorized) return false; IIdentity user = httpContext.User.Identity; CPrincipal cPrincipal = new CPrincipal(user); httpContext.User = cPrincipal; return true; } }
Then replace all AuthorizeAttributes with the custom version.
Option 1 handles everything around the world, and Option 2 handles everything on a more individual level using filters.
Personally, I decided to use the global.asax method, so I have user primary access available all over the world. Here is the actual code that resolved my issue:
protected void Application_AuthorizeRequest(object source, EventArgs e) { if(User.Identity.IsAuthenticated && Roles.Enabled) { using (EntityContext db = new EntityContext ()) { var user = db.Users.Include("Roles").SingleOrDefault(u => u.ADName.Equals(User.Identity.Name)); if (user == null) return; PcsPrincipal principal = new PcsPrincipal((WindowsIdentity)User.Identity, user); Context.User = principal; } } }