asp.net

位置:IT落伍者 >> asp.net >> 浏览文章

ASP.NET防盗链演示代码


发布日期:2021年02月21日
 
ASP.NET防盗链演示代码

<%@ WebHandler Language=C# Class=防盗链 %>

using Systemusing SystemWeb

public class 防盗链 IHttpHandler {

public void ProcessRequest (HttpContext context) { contextResponseContentType = image/JPEGstring fullpath = HttpContextCurrentServerMapPath(~/image/jpgusing (SystemDrawingBitmap bitmap = new SystemDrawingBitmap(fullpath))

{ using (SystemDrawingGraphics g = SystemDrawingGraphicsFromImage(bitmap))

{ if (contextRequestUrlReferrer == null)

{ gClear(SystemDrawingColorWhite)gDrawString(禁止提交图片 new SystemDrawingFont(宋体 SystemDrawingBrushesRosyBrown } else if(context RequestUserHostAddress !=localhost||context Request UserHostAddress !=

{ gClear(System Drawing Color White )gDrawString(禁止盗链new SystemDrawingFont (宋体System Drawing Brushes RosyBrown }

} bitmapSave(context Response OutputStream System Drawing Imaging ImageFormatGif )}

public bool IsReusable { get { return false}

}

上一篇:ASP.NET底层架构探索之进入ASP.NET

下一篇:ASP.Net之C#中的异常处理