我的网站上有一个用于缓存大型flash电影的文件夹,我想阻止其他人将它们嵌入到他们的网站中;我想尝试仅使用web.config
文件执行此操作。怎么可以这样做?
我对规则的第一次尝试(不起作用):
以下规则应该阻止公共访问(和嵌入)缓存文件夹“CurrentCache”中的.swf文件 - http://myurl.com/ContentCache/,并改为替换电影“NoEmbedFromCacheSWF.swf”。
<rule name="Prevent SWF hotlinking" enabled="true">
<match url="^(ContentCache)(.swf)$" ignoreCase="true" />
<conditions>
<add input="{HTTP_REFERER}" pattern="^http://(.*\.)?myurl\.com/.*$" negate="true" />
</conditions>
<action type="Rewrite" url="/Content/Flash/NoEmbedFromCacheSWF.swf" />
</rule>
提前致谢!
注意:我认为<match url="A swf inside /ContentCache/" ignoreCase="true" />
行中有正则表达式错误,任何想法应该是什么?
答案 0 :(得分:3)
您可以为此构建HttpModule
。有一篇博客文章描述了我想要做的事情:
HttpModule to block external referrers in ASP.NET
修改:我当然只关注web.config
这里的规则。您必须使用外部模块,但只能在不修改任何代码的情况下从web.config
引用它。
Edit2:如果您想使用重写规则来执行此操作,则必须更改模式,如下所示:
<rule name="Prevent SWF hotlinking" enabled="true">
<match url="/ContentCache/.*\.swf$" ignoreCase="true" />
<conditions>
<add input="{HTTP_REFERER}" pattern="^http://(.*\.)?myurl\.com/.*$" negate="true" />
</conditions>
<action type="Rewrite" url="/Content/Flash/NoEmbedFromCacheSWF.swf" />
</rule>
使用的模式是正则表达式,您可以阅读它们here,然后您可以在this webpage上测试它们。