0

I have an ASP.net application hosted on IIS 7.5 and would like to find out within the application if anonymous access is enabled for this app.

I thought this would deliver:

AnonymousAuthenticationSection section = WebConfigurationManager.OpenSection("system.webServer/security/authentication/anonymousAuthentication") as AnonymousAuthenticationSection;
return section.Enabled;

But section is always null, even if it seems that the relating part in the applicationHost.config looks good:

<location path="Default Web Site/TestApp">
    <system.webServer>
        <security>
            <authentication>
                <anonymousAuthentication enabled="false" userName="" />
                <windowsAuthentication enabled="true">
                    <providers>
                        <clear />
                        <add value="NTLM" />
                        <add value="Negotiate" />
                    </providers>
                </windowsAuthentication>
            </authentication>
        </security>
    </system.webServer>
</location>

Could anyone tell me why this is null? Thanks.

Powerslave
  • 139
  • 1
  • 11
  • What happens when you try something like in [http://stackoverflow.com/questions/2661425/how-do-i-programmatically-set-integrated-windows-authentication-in-iis-on-a-net/3414507#3414507](http://stackoverflow.com/questions/2661425/how-do-i-programmatically-set-integrated-windows-authentication-in-iis-on-a-net/3414507#3414507)? – eoszak Nov 13 '13 at 13:53
  • This kind of works, but I'd have to deploy Microsoft.Web.Administration.dll which is not part of .NET 4.0. – Powerslave Nov 13 '13 at 14:01

0 Answers0