【问题标题】:Block web access to a single subfolder using IIS?使用 IIS 阻止对单个子文件夹的 Web 访问?
【发布时间】:2020-01-27 08:22:59
【问题描述】:

我想阻止从 Web 访问网站上的 logs 子文件夹。以下web.config 似乎有效...

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

...但它也会阻止访问所有子文件夹中的任何logs 文件夹(foo/logsfoo/bar/logs 等)。

如何仅阻止与 web.config 文件位于同一文件夹中的 logs 文件夹?

我知道我可以将web.config 文件直接放在logs 目录中,但这不是这里的选择,因为当有人擦除日志文件时它很可能会被意外擦除。

【问题讨论】:

  • 使用 URL 重写模块将不需要的请求重定向到错误页面,或者简单地中止它们。

标签: iis iis-7 web-config iis-8 requestfiltering


【解决方案1】:

您可以通过 iis url 重写规则来阻止对特定文件夹的请求。

以下是规则:

  <rule name="RequestBlockingRule16" stopProcessing="true">
                <match url=".*" />
                <conditions>
                    <add input="{URL}" pattern="^/s2/(.*)" />
                </conditions>
                <action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="You do not have permission to view this directory or page using the credentials that you supplied." />
            </rule>

文件夹结构:

s1 是站点根文件夹。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-18
    • 2014-07-21
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多