如何在Web.Config中禁用目录浏览

Gib*_*boK 21 asp.net iis web-config

我有一个WebSite,我喜欢来自web.config文件的拒绝目录浏览器.

这里我使用的代码放在ROOT中.不行.我正在本地测试它所以使用URL LIKE http:// localhost:3214 /我仍然可以浏览CMS的目录.

  • 我做错了什么?
  • 它应该在本地机器上工作吗?

感谢您的支持!

<configuration>
  <location path="Cms">
    <system.webServer>
      <directoryBrowse enabled="false" />
    </system.webServer>
  </location>
</configuration>
Run Code Online (Sandbox Code Playgroud)

一些资源:

http://blogs.iis.net/bills/archive/2008/03/24/how-to-enable-directory-browsing-with-iis7-web-config.aspx

http://www.expta.com/2008/03/configuring-virtual-directories-with.html

Ric*_*ard 7

第一:不是所有的东西都在<location>块中运作.

我找不到a <system.webServer>中不支持的肯定声明<location>,但我找不到任何建议允许它的情况.对此的证据是在(全局)中machine.config,该system.webserver部分被定义为使用IgnoreSection处理程序:即.它不是由标准System.Configuration实现处理的,而是为配置处理提供支持的标准实现<location>.

尝试将a添加web.configCms包含该directoryBrowse元素的文件夹中,以确认浏览被阻止.


Moh*_*lam 5

Gibbok,这里没有错,请不要惊慌:)

假设您是从Visual Studio的内置服务器浏览网站,通常是正常情况。

我很确定,如果您使用上述代码移至IIS,目录浏览的行为将与您希望的一样。

试试看,并在IIS中托管该网站,让我们知道发生了什么,谢谢。