【发布时间】: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>
【问题讨论】: