20

In IIS7 under Windows Server 2008, I have a virtual directory with anonymous access off and Windows authentication on. In my web.config, I have:

<authentication mode="Windows"/>
<authorization>
            <allow roles="MYGROUP"/>
            <deny users="*"/>
</authorization>

and

<system.webServer>
    <!-- IIS7 security settings -->
    <security>
        <authorization>
                <add accessType="Deny" users="*"/>
                <add accessType="Allow" roles="MYGROUP"/>
        </authorization>
    </security>
</system.webServer>

Yet when I access default.aspx from IE and set a breakpoint in Global.asax.vb Application_AuthenticateRequest(), I get a null HttpContext.Current.User where I am expecting my own identity. It is almost as if Anonymous Access is on?

What can I do to troubleshoot this? Everything seems to work in IIS6.

3
  • BTW, I looked here: codesnip.net/iis7-integrated-windows-authentication-win-2008 -- and everything looks good according to that. Nov 2, 2009 at 21:07
  • Did you ever figure out a solution to this? Having the same issue, and this is the closest question I can find on the topic.
    – Jerad Rose
    Jan 3, 2011 at 22:58
  • No--it has something to do with the new way IIS works, in that it can pass control to your ASP.NET program to do its authentication. I still need someone to explain it to me in more layman's terms, I'd guess. Jan 4, 2011 at 22:26

4 Answers 4

29

The answer to of moving the Application Pool back to classical is just delaying the problem.

Instead leave the application pool alone and move your authenticate check from Application_AuthenticateRequest(), to the next function in the pipeline:

Application_AuthorizeRequest(object sender, EventArgs e)

By then the integrated Application Pool has completed the windows authentication allow you not to receive null from HttpContext.Current.User.

The pipeline can be found here (link provided by CarlosAg).

A visualization of the pipeline can be found on the asp website message lifecycle page. In the controller section checkout the two green boxes "Authentication filters" and "Authorization filters". These are the areas you are messing with.

0
2

II7 has integrated authentication. You can set it back to the old type by changing the Application Pool back to classical in the basic settings in IIS.

*Caution this is just an explanation and example, you may want to use the integrated authentication and do something different.

8
  • I must be missing something--IIS6 had "Integrated Windows Authentication" too. It is the first option under Authenticated Access in Directory Security > Authentication and access control > edit. What am I missing? Nov 2, 2009 at 21:08
  • I didn't think what I am trying to do is "old type"--surely Microsoft isn't phasing out Windows Authentication. Where can I see info on the "new way" of doing authentication? Nov 2, 2009 at 21:12
  • @Patrick: In II6 there were two levels of Authentication that were hit for each .NET request. First the windows one, then the ISAPI would find out it was a .NET request and then .NET would do its own Authentication. In IIS7 .NET was integrated into the Web Server and now there is only one Authentication. As far as I understand it. MSDN would likely be the unfortunate choice for the new way, if you don't want to go with the old way. Nov 2, 2009 at 21:21
  • Does this new way have a name so that I can search for it? Everything I search for seems to be referring to the old way. Nov 2, 2009 at 21:26
  • 3
    You should read information about classic vs integrated, see learn.iis.net/page.aspx/243/aspnet-integration-with-iis-7 Integrated mode is much better, and it will have less duplication. The reason this used to work was because IIS would perform "AuthenticateRequest" way before ASP.NET would even see the request. In integrated, ASP.NET becomes 1st class in IIS and it will see the "BeginRequest and AuthenticateRequest" at the same time that IIS does. This causes some changes (correct changes I should add), which means some applications that leveraged the wrong behavior might fail. Oct 28, 2010 at 17:24
2

With IIS 7 and asp.net 4.0 the user was still null within Application_AuthenticateRequest() (object sender, EventArgs e). I had to place all authentication logic within the Application_PostAuthenticateRequest() (object sender, EventArgs e). You can see an example here context-user-is-null-in-application-authenticaterequest-via-windows-auth-in-asp

1
  • Application_AuthorizeRequest is after Application_PostAuthenticateRequest and after Application_AuthenticateRequest. Authorization should be done/checked in authorization not authenticate Jan 10, 2014 at 14:44
1

Anonymous access must be on if you don't use ssl or something your own security.

1
  • 2
    @AustinHenley, new users aren't allowed to post comments here.
    – Sam
    Oct 17, 2013 at 5:48

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.