以下是场景,我有一个使用自定义身份验证和成员资格提供程序的 Asp.Net 应用程序,但我们需要允许完全匿名访问(即)应用程序中的特定文件夹。
在 IIS 管理器中,您可以设置文件夹的身份验证模式,但设置保存在 C:\Windows\System32\inetsrv\config\applicationHost.config
文件 as described here 中
为了使安装更容易,如果我可以在 web.config 中设置它,那就太好了,但经过几次尝试后,我认为这可能是不可能的。
还有人知道吗?
非常感谢
最佳答案
第一种方法是使用 <location>
修改您的 web.config配置标签,和 <allow users="?"/>
允许匿名或 <allow users="*"/>
对于所有人:
<configuration>
<location path="Path/To/Public/Folder">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
</configuration>
如果该方法不起作用,那么您可以采用以下方法,该方法需要对 IIS applicationHost.config 进行少量修改。
首先,在 C:\Windows\System32\inetsrv\config\applicationHost.config 中将匿名身份验证部分的 overrideModeDefault 从“拒绝”更改为“允许”:
<section name="anonymousAuthentication" overrideModeDefault="Allow" />
overrideMode
是 IIS 的一项安全功能。如果 applicationHost.config 中的系统级别不允许覆盖,则您无法在 web.config 中执行任何操作来启用它。如果您在目标系统上没有此级别的访问权限,则必须与您的托管提供商或系统管理员进行讨论。
二、设置overrideModeDefault="Allow"
后然后你可以将以下内容放入你的 web.config 中:
<location path="Path/To/Public/Folder">
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="true" />
</authentication>
</security>
</system.webServer>
</location>
关于asp.net - 允许对 web.config 中的单个文件夹进行匿名身份验证吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10351075/