webconfig 集成配置采用hander注入
MyHanders代码实现
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
this.IsReusable = true; var httpRequest = context.Request; var urlReferrer = httpRequest.UrlReferrer; if (urlReferrer == null || string.IsNullOrEmpty(urlReferrer?.ToString())) { context.Response.ContentType = "image/jpeg"; context.Response.WriteFile("~/image/404.jpg"); } else { if (urlReferrer.Host.Contains("localhost")) { string urlPath = httpRequest.AppRelativeCurrentExecutionFilePath; string urlPathValues = context.Server.MapPath(urlPath); if (System.IO.File.Exists(urlPathValues)) { context.Response.ContentType = "image/jpeg"; context.Response.WriteFile(httpRequest.AppRelativeCurrentExecutionFilePath); } else { context.Response.ContentType = "image/jpeg"; context.Response.WriteFile("~/image/404.jpg"); } } }