在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
首先建一个类:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Drawing; /// <summary> ///Class1 的摘要说明 /// </summary> public class Class1:IHttpHandler //调用接口 { public Class1() { // //TODO: 在此处添加构造函数逻辑 // } public bool IsReusable { get { return true; } } public void ProcessRequest(HttpContext context) { HttpRequest req = context.Request; if (req.UrlReferrer != null && req.UrlReferrer.Host.Length > 0) //反盗链代码判断 { System.Drawing.Image img = System.Drawing.Image.FromFile(context.Request.PhysicalPath); System.Drawing.Graphics g = Graphics.FromImage(img); g.DrawString("三国演义", new Font("宋体", 20, FontStyle.Bold), Brushes.White, 10, 10); img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); context.Response.Flush(); context.Response.End(); } else { context.Response.Write("您不能盗链本站图片"); } } }
<httpHandlers> <add verb="*" path="images/*.jpg" type="Class1,App_Code"/> </httpHandlers> 参考: 1.修改web.config
2.添加一个一般执行文件Watermark.ashx,代码如下: |
请发表评论