using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; /// /// myhandler 的摘要说明 /// public class myhandler:IHttpHandler { public void ProcessRequest(HttpContext context) { string FileName = context.Server.MapPath(context.Request.FilePath); string host = context.Request.UrlReferrer.Host; if (context.Request.UrlReferrer.Host == null) { context.Response.ContentType = "image/JPEG"; context.Response.WriteFile("~/error.gif");//被替换图片 } else { if (host.IndexOf("xh100.com") > -1 || host.IndexOf("baidu.com") > -1 || host.IndexOf("bing.com") > -1 || host.IndexOf("google.com") > -1 || host.IndexOf("sogou.com") > -1 || host.IndexOf("360.cn") > -1)//这里是你的域名 { context.Response.ContentType = "image/JPEG"; context.Response.WriteFile(FileName); } else { context.Response.ContentType = "image/JPEG"; context.Response.WriteFile("~/error.gif"); } } } public bool IsReusable { get { return true; } } public myhandler() { // // TODO: 在此处添加构造函数逻辑 // } }