[C#] C#防盗链处理类 →→→→→进入此内容的聊天室

来自 , 2020-09-25, 写在 C#, 查看 96 次.
URL http://www.code666.cn/view/28f72417
  1. /// <summary>
  2. /// 访盗链的FileHandler
  3. /// </summary>
  4. public class FileHandler:IHttpHandler
  5. {
  6. public FileHandler()
  7. {
  8. //
  9. // TODO: 在此处添加构造函数逻辑
  10. //
  11. }
  12.  
  13.   public void ProcessRequest(HttpContext context)
  14.   {
  15.   if ((context.Request.UrlReferrer == null) || (context.Request.UrlReferrer.Host == "localhost" && context.Request.UrlReferrer.Port == 16490))
  16.   {
  17.   context.Response.Expires = 0;
  18.   context.Response.Clear();
  19.   context.Response.ContentType = "rar";
  20.   context.Response.WriteFile(context.Request.PhysicalPath);
  21.   context.Response.End();
  22.   }
  23.   else //如果不是本地引用,则属于盗链引用,
  24.   {
  25.  
  26.   HttpResponse response = context.Response;
  27.   response.Redirect(context.Request.ApplicationPath + "/ErrorPage.htm");
  28.   }
  29.  
  30.   }
  31.   public bool IsReusable
  32.   {
  33.   get
  34.   {
  35.   return false;
  36.   }
  37.   }
  38. }
  39. //csharp/826

回复 "C#防盗链处理类"

这儿你可以回复上面这条便签

captcha