图片、文件防盗链程序 关于图片盗链这个问题,毕竟是自己的劳动成功,很多人不希望别人就那么轻易地偷走了。 这个功能在很多的论坛上都具有,可能是因为盗链的行为太多了吧 反盗链的程序其实很简单,熟悉ASP.NET 应用程序生命周期的话很容易就可以写一个,运用HttpModule在BeginRequest事件中拦截请求就ok了,剩下的工作就是过滤,再过滤! 如果不熟悉HttpModule的话,可以去MSDN上查阅,介绍非常详细,地址:ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_aspnetcon/html/f1d2910f-61d0-4541-8af8-c3c108ca351f.htm。这里就不废话了
1private void Application_BeginRequest(Object source, EventArgs e) 2{ 3 HttpApplication application = (HttpApplication)source; 4 HttpContext context = application.Context; 5 bool isSafe = true; //是否合法链接 6 string uri = context.Request.Url.AbsolutePath.ToLower(); 7 if (uri.LastIndexOf(".") > 0 && context.Request.UrlReferrer != null) 8 { 9 string exp = uri.Substring(uri.LastIndexOf("."));10 //这里是判断文件后缀名是否在排除的文件类型列表之内11 bool isHas = ClassLibrary.RData.RString.StrIsIncUseSC(exp, config.ImgSafeType.Split(''));12 if (isHas)13 {14 string domainOutter = context.Request.UrlReferrer.Authority.ToLower(); //包含域名和端口15 ArrayList arry = Common.Cache.GetDomainValid();//取系统定义的合法的域名绑定列表16 isSafe = arry.Contains(domainOutter); //判断当前请求的域名是否在合法列表之内17 }18 }19 //下面就是不合法的时候的输出了,如果有默认替代图片则输出,如果没有就生成一个,格式为.gif20 if (!isSafe)21 {22 Bitmap img = null;23 Graphics g = null;24 MemoryStream ms = null;2526 try27 {28 string picPath = ClassLibrary.RPath.GetFullDirectory("images/unlawful.gif");29 if (File.Exists(picPath))30 {31 img = new Bitmap(picPath, false);32 }33 else34 {35 img = new Bitmap(64, 64);36 g = Graphics.FromImage(img);37 g.Clear(Color.White);38 Font f = new Font("宋体,黑体,Arial", 9,FontStyle.Bold);39 SolidBrush s = new SolidBrush(Color.Red);40 g.DrawString(Resources.Message.LawlessLink, f, s, 1, 20);41 img.Save(picPath, ImageFormat.Gif);42 }43 ms = new MemoryStream();44 img.Save(ms, ImageFormat.Gif);45 context.Response.ClearContent();46 context.Response.ContentType = "image/Gif";47 context.Response.BinaryWrite(ms.ToArray());48 context.Response.End();49 }50 catch51 { }52 finally53 {54 if(g != null )55 g.Dispose();56 img.Dispose();57 }58 }59} 凡是有利必有害,这样做最大的缺点就是增加了系统开销,客户端的每一请求都要过滤一遍,性能自然要打折扣了。不知道哪位朋友有更好的办法,或者优化的方法,一起来探讨探讨。
2008年11月8日星期六
破解163相册图片防盗链秘籍时间
破解163相册图片防盗链秘籍时间:2008-10-01 来源:中国flash在线 作者:踏雪 加入收藏 错误报告
window.google_render_ad();
QQ魔法相册在线制作
QQ书签 1000){u=u.substring(0,1000);}var f=window.open(u,'tagger','width=730,height=650,scrollbars,resizable');if(null==f){d.location=u+'&__np=1';}else{f.focus();}})();">
alimama_pid="mm_10291867_1246268_2671244";
alimama_titlecolor="D71418";
alimama_descolor ="D71418";
alimama_bgcolor="FFFFFF";
alimama_bordercolor="FFFFFF";
alimama_linkcolor="D71418";
alimama_bottomcolor="FFFFFF";
alimama_anglesize="0";
alimama_bgpic="0";
alimama_icon="0";
alimama_sizecode="41";
alimama_width=120;
alimama_height=60;
alimama_type=2;
window.google_render_ad();
众所周知,163相册速度是非常快的。简直是QQ相册的好几倍。现在还有个上传工具,可以一次性上传很多张图片。fyM中国flash在线fyM中国flash在线但是有个很大缺点,就是不能别的地方链接相册里的图片(这个就称为防盗链系统),这个当然是163考虑到自己利益所以才防盗链的。fyM中国flash在线fyM中国flash在线不过,现在我便要把相册里的图片在论坛显示出来 嘿fyM中国flash在线fyM中国flash在线下面这张图片,放在163的相册里:fyM中国flash在线
图片地址是:http://img.photo.163.com/0aGxGBawsnVqSwSDZkmTxw==/790381734604264717.giffyM中国flash在线如果直接用这个地址贴出来 肯定显示不了 因为163防盗链了!如图:fyM中国flash在线fyM中国flash在线fyM中国flash在线只要在图片地址前面加上:http://www.flashline.cn/163.asp?url=fyM中国flash在线即,图片的地址变为:http://www.flashline.cn/163.asp?url=http://img.photo.163.com/0aGxGBawsnVqSwSDZkmTxw==/790381734604264717.giffyM中国flash在线就可以正常显示了!fyM中国flash在线如图:fyM中国flash在线fyM中国flash在线
window.google_render_ad();
window.google_render_ad();
QQ魔法相册在线制作
QQ书签 1000){u=u.substring(0,1000);}var f=window.open(u,'tagger','width=730,height=650,scrollbars,resizable');if(null==f){d.location=u+'&__np=1';}else{f.focus();}})();">
alimama_pid="mm_10291867_1246268_2671244";
alimama_titlecolor="D71418";
alimama_descolor ="D71418";
alimama_bgcolor="FFFFFF";
alimama_bordercolor="FFFFFF";
alimama_linkcolor="D71418";
alimama_bottomcolor="FFFFFF";
alimama_anglesize="0";
alimama_bgpic="0";
alimama_icon="0";
alimama_sizecode="41";
alimama_width=120;
alimama_height=60;
alimama_type=2;
window.google_render_ad();
众所周知,163相册速度是非常快的。简直是QQ相册的好几倍。现在还有个上传工具,可以一次性上传很多张图片。fyM中国flash在线fyM中国flash在线但是有个很大缺点,就是不能别的地方链接相册里的图片(这个就称为防盗链系统),这个当然是163考虑到自己利益所以才防盗链的。fyM中国flash在线fyM中国flash在线不过,现在我便要把相册里的图片在论坛显示出来 嘿fyM中国flash在线fyM中国flash在线下面这张图片,放在163的相册里:fyM中国flash在线
图片地址是:http://img.photo.163.com/0aGxGBawsnVqSwSDZkmTxw==/790381734604264717.giffyM中国flash在线如果直接用这个地址贴出来 肯定显示不了 因为163防盗链了!如图:fyM中国flash在线fyM中国flash在线fyM中国flash在线只要在图片地址前面加上:http://www.flashline.cn/163.asp?url=fyM中国flash在线即,图片的地址变为:http://www.flashline.cn/163.asp?url=http://img.photo.163.com/0aGxGBawsnVqSwSDZkmTxw==/790381734604264717.giffyM中国flash在线就可以正常显示了!fyM中国flash在线如图:fyM中国flash在线fyM中国flash在线
window.google_render_ad();
订阅:
博文 (Atom)