如何在 Web.Config 中禁用目录浏览 [英] How to disable Directory Browse in Web.Config

查看:87
本文介绍了如何在 Web.Config 中禁用目录浏览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,我想从 web.config 文件拒绝目录浏览器.

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

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

感谢您的支持!

<预><代码><配置><location path="Cms"><system.webServer><directoryBrowse enabled="false"/></system.webServer></位置></配置>

一些资源:

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

解决方案

第一:不是所有的东西都在 块中工作.

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

尝试将 web.config 添加到带有 directoryBrowse 元素的 Cms 文件夹中,以确认浏览被阻止.

I have a WebSite and I woud like Deny Directory Browser from a web.config file.

Here the code I'm using placed in the ROOT. Does not work. I'm testing it Locally so with URL LIKE http://localhost:3214/ I can still browser the directory fro CMS.

  • What I'm doing wrong?
  • Should it work even on Local Machine?

Thanks for your support!

<configuration>
  <location path="Cms">
    <system.webServer>
      <directoryBrowse enabled="false" />
    </system.webServer>
  </location>
</configuration>

Some resource:

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

解决方案

First: not everything works in a <location> block.

I cannot find a positive statement that <system.webServer> isn't supported in a <location>, but I cannot find any cases where it is suggested that it is allowed. Evidence for this is in the (global) machine.config where the system.webserver section is defined to use the IgnoreSection handler: ie. it isn't processed by the standard System.Configuration implementation, and it is that standard implementation of config handling that provides support for <location>.

Try adding a web.config into the Cms folder with the directoryBrowse element to confirm that browsing is blocked.

这篇关于如何在 Web.Config 中禁用目录浏览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆