ASP.NET IHttpModule IHttpHandler IHttpHandler Factoryブロック要求

7884 ワード

まずコードを見て、すべてのHttpリクエストクラスをブロックします.以下に2種類の統合IHttpModule IHttpHandlerFactoryを含む
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SoonnetWebSite
{
    /// 
    /// Handler2      
    /// 
    public class Handler2 : IHttpModule
    {
        public void Dispose()
        {
        }

        private void Application_AcquireRequestState(Object source, EventArgs e)
        {
            HttpApplication httpApplication = (HttpApplication)source;
            string url = httpApplication.Context.Request.Path.ToLower();
            string imgPhysicalPath = httpApplication.Request.Url.ToString();
            if (imgPhysicalPath.ToLower().IndexOf("https") != 0 && imgPhysicalPath.IndexOf("Video/VideoUpload.aspx") == -1 && imgPhysicalPath.IndexOf("Photo/PhotoUpload.aspx") == -1)
            {
                imgPhysicalPath = imgPhysicalPath.Replace("http", "https");
                httpApplication.Response.Redirect(imgPhysicalPath);
                return;
            }
            // httpApplication.Response.Redirect(imgPhysicalPath);
        }


        public void Init(HttpApplication context)
        {
            context.AcquireRequestState += (new EventHandler(this.Application_AcquireRequestState));
        }
        //public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        //{
        //    IHttpHandler handler = null;
        //    string action = url.Substring(url.LastIndexOf("/", StringComparison.Ordinal) + 1);
        //    action = action.Substring(0, action.IndexOf(".", StringComparison.Ordinal));
        //    var Rurl = context.Request.RawUrl.Replace("/", ".");
        //    string actionClass = $"SoonnetWebSite.{Rurl}";
        //    if (true)
        //    {

        //    }
            
        //}

        //public void ReleaseHandler(IHttpHandler handler)
        //{
        //    throw new NotImplementedException();
        //}
    }
}

  
IHttpHandlerを見てみましょう
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace SoonnetWebSite
{
    /// 
    /// Handler1      
    /// 
    public class Handler1 : IHttpHandler
    {
        private const string DEFAULTIMAGE_URL = "/SGL_Images/Userlogo_Big.jpg";
        public void ProcessRequest(HttpContext context)
        {
            string imgPhysicalPath = context.Request.Url.ToString();
            string rawUrl = context.Request.RawUrl.ToString();
            System.Drawing.Image image = null;
            if (File.Exists(context.Server.MapPath(rawUrl)))
            {                         //  
                image = System.Drawing.Image.FromFile(context.Server.MapPath(rawUrl));
            }
            else
            {             //
                image = System.Drawing.Image.FromFile(context.Server.MapPath(DEFAULTIMAGE_URL));
            }
            //             
            context.Response.ContentType = "image/jpeg";
            //                
            image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            image.Dispose();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

两端代码的配置如下

  
    
      
        
      
    
    
    
      
      
      
    
    
      
    
  

IIS構成がネイティブでテストしたノードとは異なるという問題が見つかりました.ライン上の構成は

    
      
        
      
    
    
    
      
      
      
    
    
      
    
  

前の構成にhttpが1つ増えました
IISの古典的なモードと集積モードの関係から、
参照リンク:https://blog.csdn.net/hongwei_23/article/details/44300923
 
http転送httpリファレンスリンク:https://blog.csdn.net/suxuelian/article/details/80103514
転載先:https://www.cnblogs.com/Mrly/p/11497671.html