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     }
  • 相关阅读:
    GitHub指南
    团队管理之愿景
    软件开发中的思维僵化
    疯狂的 JAVA 后++
    Spring MVC ajax:post/get 的具体实现
    ReentrantLock的Condition使用问题
    Scala学习(一)
    Tomcat源码分析(一)
    LeetCode -- Word Break 动态规划,详细理解
    Javascript 闭包访问问题?
  • 原文地址:https://www.cnblogs.com/oneroom/p/nosteal.html
Copyright © 2011-2022 走看看