标签:
public void ProcessRequest(HttpContext context) { context.Response.ContentType="image/jpeg"; //当前请求 Uri url = context.Request.Url; //上一次请求 Uri referrer = context.Request.UrlReferrer; if (CompareUrl(url,referrer)) { //合法 //string path = context.Request.MapPath(context.Request.RawUrl); context.Response.WriteFile(url.AbsoluteUri); } else { string path = context.Request.MapPath("daolian.jpg"); context.Response.WriteFile(path); } } private bool CompareUrl(Uri u1, Uri u2) { return Uri.Compare(u1, u2, UriComponents.HostAndPort, UriFormat.SafeUnescaped, StringComparison.CurrentCultureIgnoreCase) == 0; }
<system.web> <httpHandlers> //此处的type中全写 第一个参数是 命名空间+类 第二个参数是程序集名称 path为访问哪个文件夹中的文件 <add verb="*" type="FangDaoLian" path="images/*.jpg"/> </httpHandlers> </system.web>
标签:
原文地址:http://www.cnblogs.com/netaming/p/4489233.html