使用Image Resizer ASP.NET MVC保护图像

时间:2017-01-23 10:05:01

标签: asp.net-mvc imageresizer

我使用imageresizer for ASP.NET。当我拍照时,我把我们的品牌。但是我怎样才能保护原始图片。 例如:

http://www.domain.com/mypic.jpg

但是一个人可以从我List<int> integers = strings.ConvertAll(s => Int32.Parse(s)); 我的原始照片中获取原始照片吗?

谢谢。

2 个答案:

答案 0 :(得分:1)

有很多方法,你如何做“热链接保护”。其中之一是使用重写规则。如果有人试图在另一个网站上链接你的图片,它会显示no_hotlinking_allowed.jpg图片:

<rewrite>
        <rules>
            <rule name="Hotlinking protection">
                <match url=".*\.(gif|jpg|png)$" />
                <conditions>
                    <add input="{HTTP_REFERER}" pattern="^$" negate="true" />
                    <add input="{HTTP_REFERER}" pattern="^http://(.*\.)?domain\.com/.*$" negate="true" />
                </conditions>
                <action type="Rewrite" url="/images/no_hotlinking_allowed.jpg" />
            </rule>
        </rules>
    </rewrite>

这是通用的方式,它与imageresizer无关

如果你想保护对没有水印问号的图像的访问,这个规则适合你:

<rule name="Autoadd watermark">
                <match url=".*\.(gif|jpg|png)$" />
                <conditions>
                    <add input="{QUERY_STRING}" pattern=".*watermark.*" negate="true" />

                </conditions>
                <action type="Rewrite" url="{PATH_INFO}?watermark=watermark" />
            </rule>

答案 1 :(得分:0)

您可以向ImageResizer添加自定义授权规则,以便它只提供带水印的图像:

ImageResizer.Configuration.Config.Current.Pipeline.AuthorizeImage += 
    delegate(IHttpModule sender, HttpContext context, IUrlAuthorizationEventArgs e)
    {
        // You can also check that you support specific watermark parameter value.
        if ( string.IsNullOrEmpty(context.Request.QueryString["watermark"] ) )
        {
            e.AllowAccess = false;
        }
    };

有关详细信息,请查看ImageResizer events documentation