asp.net下结合HttpHandler实现图片防盗链
asp.net下结合HttpHandler实现图片防盗链
发布时间:2016-12-29 来源:查字典编辑
摘要:复制代码代码如下:#regionIHttpHandler成员boolIHttpHandler.IsReusable{get{returntr...

复制代码 代码如下:

#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>

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新asp.net教程学习
热门asp.net教程学习
编程开发子分类