C#图片防盗链
2008-02-25 22:33
344 查看
1 写一个继承自IHttpHandler的类,并生成DLL;
using System;
using System.Web;
using System.Collections.Generic;
using System.Text;
namespace ImgProtect
{
public class ImgProtectHadler:IHttpHandler
{
public bool IsReusable
{
get
{
return true;
}
}
public void ProcessRequest(HttpContext context)
{
string path = context.Request.PhysicalPath;
string serverHost = context.Request.Url.Host;
Uri u = context.Request.UrlReferrer;
if (u == null || u.Host.ToLower() != serverHost.ToLower())
{
context.Response.WriteFile("~/Forbidden.gif");
}
else
{
context.Response.WriteFile(path);
}
}
}
}
2 在网站中引用 该DLL;
3 在Web.config中加入
<httpHandlers>
<add verb="*" path="*.jpg,*.jpeg,*.gif,*.png,*.bmp" type="ImgProtect.ImgProtectHadler"/>
</httpHandlers>
using System;
using System.Web;
using System.Collections.Generic;
using System.Text;
namespace ImgProtect
{
public class ImgProtectHadler:IHttpHandler
{
public bool IsReusable
{
get
{
return true;
}
}
public void ProcessRequest(HttpContext context)
{
string path = context.Request.PhysicalPath;
string serverHost = context.Request.Url.Host;
Uri u = context.Request.UrlReferrer;
if (u == null || u.Host.ToLower() != serverHost.ToLower())
{
context.Response.WriteFile("~/Forbidden.gif");
}
else
{
context.Response.WriteFile(path);
}
}
}
}
2 在网站中引用 该DLL;
3 在Web.config中加入
<httpHandlers>
<add verb="*" path="*.jpg,*.jpeg,*.gif,*.png,*.bmp" type="ImgProtect.ImgProtectHadler"/>
</httpHandlers>
相关文章推荐
- asp.net HttpHandler实现图片防盗链
- CSS实现简单的图片防盗链代码
- 绕过图片防盗链的方法_实测可用
- 图片地址防盗链,通过IHttpHandler实现
- php实现博客,论坛图片防盗链的方法
- 图片、文件防盗链程序
- 图片、文件防盗链程序
- nginx实现图片防盗链(referer指令)
- nginx设置图片防盗链
- 图片、文件防盗链
- 【破解】图片防盗链破解 ASP源码奉上
- Global.asax或IHttpModule实现屏蔽ip和图片防盗链
- 实现页面图片防盗链
- asp.net中利用ashx实现图片防盗链
- nginx针对不是图片的文件添加防盗链
- 自制小型图片采集程序(绕过防盗链)
- apache图片防盗链例子
- [置顶] 让 "图片防盗链" 见鬼去吧
- ASP.NET 图片加水印防盗链
- ASP.NET 图片防盗链的实现原理分析