Search code examples
c#asp.netvisual-studioweb-configiis-express

How can I properly activate Windows authentication prompt in ASP.NET?


I have a ASP.NET site that should use Windows authentication. I've modified web.config to include the following code:

<system.web>
    <authentication mode="Windows" />
    <authorization>
        <allow roles="domain\application users"/>
        <deny roles="domain\domain users" />
    </authorization>
</system.web>

I've been able to get this same exact code to work in another ASP.NET application. However, this application doesn't even prompt for credentials and lets all users through during debug in Visual Studio using IIS Express; it's like Windows authentication isn't actually registering.

I've used HttpContext.Current.User.Identity.IsAuthenticated in the codebehind to make sure my assumption is correct and it does return false.

I'm unsure whether Windows authentication works in the released version because I don't want to deploy it while it isn't working as intended.

What could I be missing here? Is there something wrong with my code or do I need to do something to correctly configure IIS?


Solution

  • I eventually stumbled across another question (Windows Authentication not working in existing asp.net site) which helped me out - I was correctly configuring my site but had decided after creating the project to add Windows authentication, meaning that it wasn't configured correctly in the solution properties themselves. Changing Windows Authentication to Enabled and Anonymous Authentication to Disabled in the Development Server properties fixed my issue.