zoukankan      html  css  js  c++  java
  • 图片防盗链asp.net 实现

    代码
     1  public class UrlHandler : IHttpHandler
     2     {
     3         //指明该HttpHandler的实现类是否需要缓存
     4         public bool IsReusable
     5         {
     6             get { return true; }
     7         }
     8         public UrlHandler()
     9         {
    10         }
    11         public void ProcessRequest(HttpContext context)
    12         {
    13             string FileName = context.Server.MapPath(context.Request.FilePath);
    14             if (context.Request.UrlReferrer == null)
    15             {
    16                 context.Response.ContentType = "image/JPEG";
    17                 context.Response.WriteFile("~/no.jpg");//被替换图片
    18             }
    19             else
    20             {
    21                 if (context.Request.UrlReferrer.Host.IndexOf("localhost"> -1)//这里是你的域名,如www.maticsoft.com
    22                 {
    23                     context.Response.ContentType = "image/JPEG";
    24                     context.Response.WriteFile(FileName);
    25                 }
    26                 else
    27                 {
    28                     context.Response.ContentType = "image/JPEG";
    29                     context.Response.WriteFile("~/no.jpg");
    30                 }
    31             }
    32         }        
    33     }
  • 相关阅读:
    软工1816 · 第四次作业
    Alpha 冲刺 (3/10)
    Alpha 冲刺 (2/10)
    Alpha 冲刺 (1/10)
    软工 第七次作业
    软工实践第八次作业
    软工实践第六次作业——团队选题报告
    软工实践第二次结对作业(作业五)
    软工第四次作业
    软工实践第三次作业
  • 原文地址:https://www.cnblogs.com/oneroom/p/nosteal.html
Copyright © 2011-2022 走看看