asp.net下结合HttpHandler实现图片防盗链
更新时间:2010年07月02日 20:00:18 作者:
asp.net防图片盗链HttpHandler
复制代码 代码如下:
#region IHttpHandler 成员
bool IHttpHandler.IsReusable
{
get { return true; }
}
void IHttpHandler.ProcessRequest(HttpContext context)
{
string FileName = context.Server.MapPath(context.Request.FilePath);
if (context.Request.UrlReferrer.Host == null)
{
context.Response.ContentType = "image/JPEG";
context.Response.WriteFile("/no.jpg");
}
else
{
if (context.Request.UrlReferrer.Host.IndexOf("mydomain.com") > 0)
{
context.Response.ContentType = "image/JPEG";
context.Response.WriteFile(FileName);
}
else
{
context.Response.ContentType = "image/JPEG";
context.Response.WriteFile("no/jpg");
}
}
}
#endregion
<httpHandlers>
<add verb="*" path="*.jpg" type="JpgHandler, MyDll" />
</httpHandlers>
相关文章
.Net笔记:System.IO之windows文件操作的深入分析
本篇文章是对.Net中windows文件操作的使用进行了详细的分析介绍,需要的朋友参考下2013-05-05
利用ASP.NET MVC和Bootstrap快速搭建个人博客之文章打赏功能(六)
这篇文章主要介绍了利用ASP.NET MVC和Bootstrap快速搭建个人博客之文章打赏功能(六) 的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下2016-07-07


最新评论