如何防止ASP.NET站点的图像热链接?

Dea*_*unt 5 asp.net http hotlinking

什么是阻止人们从托管的ASP.NET网站链接图像的最佳/最简单的方法?我不需要阻止所有图像/资源进行热链接,我只是想阻止热链接到网站上的特定图像/资源.仅供参考.这是在GoDaddy.com上的主持人因此IIS技巧可能不会工作.

小智 9

最简单的方法是使用IIS 7.0中的UrlRewrite.

https://help.maximumasp.com/KB/a738/using-url-rewrite-to-prevent-image-hotlinking.aspx

<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="PreventImageHotlinking" enabled="true" stopProcessing="true">


<match url=".*\.(gif|jpg|png)$" />
  <conditions>
                        <add input="{HTTP_REFERER}" negate="true" pattern="^$" />
                        <add input="{HTTP_REFERER}" negate="true" pattern="http://www.YourDomain.com/.*" />
  </conditions>
  <action type="Rewrite" url="/images/hotlinking.jpg" />
</rule>
            </rules>
        </rewrite>
    </system.webServer>
Run Code Online (Sandbox Code Playgroud)


Dan*_*y G 3

通过 ASPX 页面流式传输图像是一个很好的解决方案。尽管 Referrer 可能会被黑客攻击。

如果您确实关心安全性,您可以做的是使用唯一的盐(关键字)并根据 MD5(SHA-1 或 SHA-2)生成。也针对此运行当前纪元时间,这也会使图像过期。将此“密钥代码”存储在 cookie 中。每当提供图像时,您基本上都是通过查询字符串传递它。验证在另一端的 ASPX 上进行。您甚至可以使用 HTTPRequestModule 或 Global.asax 页面在每个请求之间重新生成新的“密钥代码”。

会有开销,但它会防止任何人进行盗链。