什么是完全阻止http访问应用程序子目录的最简单方法?

时间:2014-03-20 13:16:35

标签: asp.net web-config virtual-directory

我的ASP.Net应用程序包含一个子目录 foo ,不应使用http访问。我认为最简单的解决方案是将web.config放在子目录 foo 中。

<configuration>
    <system.web>
        <httpRuntime enable="false"/>
    </system.web>
</configuration>

但它不起作用。例如,服务器不会拒绝http://myapp/foo/test.html

1 个答案:

答案 0 :(得分:1)

您可以尝试在web.config中添加:

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

我测试了它似乎工作正常,当我尝试列出目录或直接访问文件时我有404.8 HTTP错误(请求过滤模块配置为拒绝包含hiddenSegment部分的URL中的路径)