asp.net下结合HttpHandler实现图片防盗链
2012奥运会乒乓球,南昌婚介,小二郎简谱
#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>
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
网友评论