我有一个托管在 IIS 7.5 上的 ASP.net 应用程序,并且想在应用程序中找出是否为此应用程序启用了匿名访问。
我认为这将提供:
AnonymousAuthenticationSection section = WebConfigurationManager.OpenSection("system.webServer/security/authentication/anonymousAuthentication") as AnonymousAuthenticationSection;
return section.Enabled;
但部分始终为空,即使 applicationHost.config 中的相关部分看起来不错:
<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>
谁能告诉我为什么这是空的?谢谢。