How to find out if anonymous access is enabled for an IIS application?

400 Views Asked by At

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.

0

There are 0 best solutions below