62,046
社区成员
发帖
与我相关
我的任务
分享
namespace Web{
public class UrlHandler : IHttpHandler
{
public bool IsReusable
{ get { return false; } }
public void ProcessRequest(HttpContext context)
{
var url = HttpContext.Current.Request.Url;
var info = string.Format("AbsolutePath:{0}<br/>AbsoluteUri:{1}<br/>", url.AbsolutePath, url.AbsoluteUri);
HttpContext.Current.Response.Write(info);
}
}
}
<httpHandler><add path="*" verb="*" type="Web.UrlHandler,Web" validate="false"/></httpHandlers>
public void ProcessRequest(HttpContext context)
{
if (null != context.Request.UrlReferrer)
{
string serverDomain = context.Request.Url.Host;
string refDomain = context.Request.UrlReferrer.Host;
//如果域名不相同,提示不要盗链
if (!GetRootDomain(refDomain).Equals(GetRootDomain(serverDomain), StringComparison.OrdinalIgnoreCase))
{
context.Response.ContentType = "text/html";
context.Response.Write(string.Format("请不要盗链。返回<a href='{0}'>{1}</a>", KMKLRequest.GetCurrentFullHost(), "文档管理系统"));
return;
}
else
{
context.Response.ContentType = "application/octet-stream";
if (Cookie.GetCookieUid() != 0 )
{
FileInfo fi = new FileInfo(context.Server.MapPath( Utils.UrlDecode( context.Request.Url.AbsolutePath)));
if (!fi.Exists)
{
fi = new FileInfo(context.Server.MapPath("~/Content/css1/images/CROSS.PNG"));
}
context.Response.TransmitFile(fi.FullName);
}
else
{
context.Response.TransmitFile(new FileInfo(context.Server.MapPath("~/Content/css1/images/DELETE.PNG")).FullName);
}
}
}
}