【问题标题】:IIS prohibit direct access to imagesIIS 禁止直接访问图像
【发布时间】:2014-09-26 10:27:42
【问题描述】:

我在 IIS 中创建了一个网站,并且根网络共享有一些子文件夹用于存储页面正在使用的图像、css、js 文件。但是,如果用户知道图像名称 (http://hello.com/images/abc.jpg),就可以访问图像。

有什么办法可以禁用对资源的直接访问?请注意,我刚刚开始学习 asp.net,所以如果答案可以有点描述性,那就太好了。

我已经了解了 URL 重写方法,但它无法正常工作。

编辑:我把这个 web.config 放在我的图像文件夹中,现在它做相反的事情,阻止页面上的图像并直接允许它们。 任何帮助表示赞赏。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <identity impersonate="true" />
    </system.web>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="RequestBlockingRule1" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url=".*\.(gif|jpg|png)$" /> 
            <conditions>
                        <add input="{HTTP_REFERER}" pattern="^$" negate="true" />
                        <add input="{HTTP_REFERER}" pattern=" http://iolab023/.*" negate="true" /> 
            </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>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

【问题讨论】:

    标签: asp.net iis-7


    【解决方案1】:

    如果您想阻止直接访问上下文(从客户端/浏览器),您可以使用配置部分来阻止它。在站点根目录的 web.config 中,您可以使用此配置来禁用“图像”子目录被访问。如果您查看您的 applicationhost.config,您会看到此部分已配置为阻止客户端直接访问“bin”文件夹。您只需在 applicationhost.config 或 web.config 中添加“图像”到该列表,如下所示。

    (如果您在 applicationhost.config 中根本看不到任何配置,这意味着您需要使用“添加/删除程序”或 Web 平台安装程序在 IIS 中安装 requestFiltering 功能)。

    <configuration>
        <system.webServer>
            <security>
                <requestFiltering>
                    <hiddenSegments applyToWebDAV="true">
                        <add segment="images" />
                    </hiddenSegments>
                </requestFiltering>
            </security>
        </system.webServer>
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 2012-02-01
      • 1970-01-01
      • 2011-09-09
      • 1970-01-01
      • 2011-04-28
      • 1970-01-01
      • 2011-10-16
      • 2011-05-11
      • 1970-01-01
      相关资源
      最近更新 更多