<%@ WebHandler Language=C# Class=防盜鏈 %>
using Systemusing SystemWeb
public class 防盜鏈 IHttpHandler {
public void ProcessRequest (HttpContext context) { contextResponseContentType = image/JPEGstring fullpath = HttpContextCurrentServerMapPath(~/image/jpg)using (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}
}
From:http://tw.wingwit.com/Article/program/net/201311/13520.html