Search code examples
asp.net-mvcasp.net-mvc-4iisiis-7windows-authentication

MVC Windows Auth Not Working


I have configured a MVC site to use windows authentication in the project properties and in the config file:

WEB CONFIG

<authentication mode="Windows"/>
  <authorization>      
      <allow users="domain_name\rbello"/>
      <deny users="?" />
  </authorization>

View Controller

 [Authorize (Users=@"domain_name\rbello, domain_name\svinstall")] 
 [Authorize(Roles = @"domain_name\administrators")]
        public ActionResult ForAdmin()
        {
           return View();
        }

When I run the code on my machine through IISExpress or when I deploy the site to IIS i get the login window but after I sign in I get an error stating "HTTP Error 401.0 - Unauthorized You do not have permission to view this directory or page"

I made sure Windows Authentication is enabled in IIS features on the project as well as on the IIS server for Windows Authentication. I also set NTLM as first provider as some had say to do. Not sure what else I been at this for a couple days now, appreciate any help!

.NET Framework 4.5 IIS 7.5 MVC 4


Solution

  • I corrected this I had a mistakenly a User value for a Role attribute example
    Incorrect: [Authorize(Roles = @"domain_name\administrators")] Corrected to: [Authorize(Roles = @"Administrators")]