IHttpHandler防止图片链接被盗用

    public class JpegHandler : IHttpHandler
{
public bool IsReusable
{
get { return true; }
} public void ProcessRequest(HttpContext context)
{
string filename = context.Server.MapPath(context.Request.FilePath);
context.Response.ContentType = "image/jpeg"; if (context.Request.UrlReferrer == null
|| context.Request.UrlReferrer.Host == null
|| !context.Request.UrlReferrer.Host.Contains("localhost")
)
{
context.Response.WriteFile("/image/error.jpg");
}
else
{
context.Request.ContentType = "image/jpeg";
context.Response.WriteFile(filename);
}
}
}

配置web.config

<add name="Jpeg" verb="*" path="*.jpg"  type="WebApplication2.JpegHandler"/>
上一篇:HDU 5344 MZL's xor (多校)[补7月28]


下一篇:spring jdbcTemplate源码剖析