web.config hiddenSegment仅用于根目录?

时间:2013-07-27 11:47:44

标签: asp.net iis web-config

我在web.config中添加了以下内容,因此用户无法下载我的插件:

<system.webServer>
    <security>
        <requestFiltering>
            <hiddenSegments>
                <add segment="Plugins" />
            </hiddenSegments>
        </requestFiltering>
    </security>
</system.webServer>

现在我遇到的问题不仅是domain.com/Plugins/MyPlugin.dll被阻止,还有domain.com/Scripts/ckeditor/plugins/ckplugin.js

有没有办法配置hiddenSegment只影响根目录?

2 个答案:

答案 0 :(得分:1)

我通过我的插件文件夹中的web.config解决了这个问题,我阻止下载* .dll文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="Plugins*.dll_*" path="*.dll" verb="*" type="System.Web.HttpForbiddenHandler" />
            <add name="Plugins*.pdb_*" path="*.pdb" verb="*" type="System.Web.HttpForbiddenHandler" />
        </handlers>
    </system.webServer>
</configuration>

答案 1 :(得分:1)

除了克里斯托夫(Christoph)的答案之外,我还做了一些其他修改,以适应我的用例,但我将其留在此处以供将来参考。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!-- Make sure this directory cannot be served. -->
  <location path="Plugins"> <!-- Change this to your path -->
    <system.webServer>
      <handlers>
        <add name="DisallowServe" path="*.*" verb="*" type="System.Web.HttpNotFoundHandler" /> <!-- Return 404 instead of 403 -->
      </handlers>
    </system.webServer>
  </location>
</configuration>