使用IIS阻止对单个子文件夹的Web访问吗?

问题描述 投票:0回答:1

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

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

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

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

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

iis iis-7 web-config iis-8 requestfiltering
1个回答
0
投票

您可以使用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>

enter image description here

enter image description here

文件夹结构:

enter image description here

enter image description here

s1是站点根文件夹。

© www.soinside.com 2019 - 2024. All rights reserved.