// 一般处理程序
<%@WebHandler Language="C#" Class="Tupian1" %>
using System;
using System.Web;
public class TuPian1 : IHttpHandler{
public void RrocessRequest (HttpContext context){
context.Response.ContentType="image/JPEG";
string fullpath=HttpContext.Current.Server.MapPath("....JPG");
using(System.Drawing.Bitmap bitmap=new System.Drawing.Bitmap(fullpath){
using(System.Drawing.Graphics g=System.Drawing.Graphics.FromImage(bitmap){
bitmap.Save(context.Response.OutputStream,System.Drawing.Imageing.ImageFormat.Jpeg);
}
}
<%@WebHandler Language="C#" Class="Tupian1" %>
using System;
using System.Web;
public class TuPian1 : IHttpHandler{
public void RrocessRequest (HttpContext context){
context.Response.ContentType="image/JPEG";
string fullpath=HttpContext.Current.Server.MapPath("....JPG");
using(System.Drawing.Bitmap bitmap=new System.Drawing.Bitmap(fullpath){
using(System.Drawing.Graphics g=System.Drawing.Graphics.FromImage(bitmap){
if(context.Request.UrlReferrer==null)
{
g.Clear(System.Drawing.Color.White);
g.DrawString("禁止直接浏览,请在页面查看",new System.Drawing.Font("宋体",30),System.Drawing.Brushes.Red,0,0);
}
}
else if(context.Request.UrlReferrer.Host!="localhost")
{
g.Clear(System.Drawing.Color.White);
g.DrawString("禁止直接浏览,请在页面查看",new System.Drawing.Font("宋体",30),System.Drawing.Brushes.Red,0,0);
}
bitmap.Save(context.Response.OutputStream,System.Drawing.Imageing.ImageFormat.Jpeg);
}
}