1.创建类库文件

Code
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace CustomHandler
{
public class CostomHandler : IHttpHandler
{
#region IHttpHandler 成员
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
string FileName= context.Server.MapPath(context.Request.FilePath);
if (context.Request.UrlReferrer.Host == null)
{
context.Response.ContentType = "image/jpeg";
context.Response.WriteFile("~/error.jpeg");
}
else
{
if (context.Request.UrlReferrer.Host.IndexOf("hist.com") > 0)
{
context.Response.ContentType = "image/jpeg";
context.Response.WriteFile(FileName);
}
else
{
context.Response.ContentType = "image/jpeg";
context.Response.WriteFile("~/error.jpeg");
}
}
}
#endregion
}
}
2.生成Dll文件
3.在将编译好的 CustomHandler.dll 拷贝到站点的 Bin 目录下
4.在Web.Config 中注册这个Handler

Code
<httpHandlers>
<add path ="*.jpeg" verb ="*" type ="CustomHandler.CostomHandler"/>
</httpHandlers>