将以下内容添加到您的根目录web.config
对于您想要保护的每个文件夹:
<location path="secure_folder">
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="false" />
<basicAuthentication enabled="true" />
</authentication>
</security>
</system.webServer>
</location>
以上假设您使用基本身份验证。
或者创建一个web.config
在每个子文件夹中,要使用几乎相同的内容进行保护(除非没有<location>
tag:
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="false" />
<basicAuthentication enabled="true" />
</authentication>
</security>
</system.webServer>
如果收到如下错误:
执行此操作时出错。
细节:
文件名:\?\d:\sites\play1\www\web.config
线路数量:15
错误:此配置节不能在此路径中使用。这
当该部分被锁定在父级别时会发生。锁定是
默认情况下 (overrideModeDefault="Deny"),或由
overrideMode="Deny" 或旧版本的位置标记
允许覆盖=“假”。
那么这意味着配置设置<anonymousAuthentication>
and <basicAuthentication>
尚未被委派读/写权限。
您可以通过启动 IIS 管理器并打开功能委派管理器来调整此设置:
当您执行此操作时,您将看到可以控制的功能列表及其委托状态:
右键单击Authentication - Anonymous
并选择Read/Write
。做同样的事情Authentication - Basic
.
此功能委派设置将在服务器上的所有站点上全局应用,但是可以使用自定义站点委派将此功能微调到特定站点。
您可以在此处阅读有关 IIS 7.x/8.0 功能委派的更多信息:
http://www.iis.net/learn/manage/managing-your-configuration-settings/an-overview-of-feature-delegation-in-iis http://www.iis.net/learn/manage/managing-your-configuration-settings/an-overview-of-feature-delegation-in-iis