zoukankan      html  css  js  c++  java
  • 管道模型图片防盗链简单实现

    webconfig 集成配置采用hander注入

    MyHanders代码实现

     this.IsReusable = true;
                var httpRequest = context.Request;
                var urlReferrer = httpRequest.UrlReferrer;
                if (urlReferrer == null || string.IsNullOrEmpty(urlReferrer?.ToString()))
                {
                    context.Response.ContentType = "image/jpeg";
                    context.Response.WriteFile("~/image/404.jpg");
                }
                else
                {
                    if (urlReferrer.Host.Contains("localhost"))
                    {
                        string urlPath = httpRequest.AppRelativeCurrentExecutionFilePath;
                        string urlPathValues = context.Server.MapPath(urlPath);
                        if (System.IO.File.Exists(urlPathValues))
                        {
                            context.Response.ContentType = "image/jpeg";
                            context.Response.WriteFile(httpRequest.AppRelativeCurrentExecutionFilePath);
                        }
                        else
                        {
                            context.Response.ContentType = "image/jpeg";
                            context.Response.WriteFile("~/image/404.jpg");
                        }
                    }
                }
    View Code
  • 相关阅读:
    周二
    周末
    简单I/O
    格式输出(1)
    c语言—变量
    水仙花数
    控制语句—循环语句
    mysql6数据库安装与配置
    如何解决Tomcat端口号被占用
    eclipse配置tomcat详细步骤
  • 原文地址:https://www.cnblogs.com/zxp6/p/11133070.html
Copyright © 2011-2022 走看看