Let's look at the code, Http requests to intercept all classes. The following two types of integration include IHttpModule IHttpHandlerFactory
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace SoonnetWebSite { /// <summary> /// Handler2 的摘要说明 /// </summary> 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(); //} } }
Let us look at IHttpHandler
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; namespace SoonnetWebSite { /// <summary> /// Handler1 的摘要说明 /// </summary> 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 (); the System.Drawing.Image Image = null ; IF (the File.Exists (context.Server.MapPath (rawUrl))) { / / empty image = System.Drawing.Image.FromFile (context.Server.MapPath (rawUrl)); } the else { // if the picture does not exist, default image put image = System.Drawing.Image.FromFile (context. the Server.MapPath (DEFAULTIMAGE_URL)); } // the type of output provided = context.Response.ContentType " Image / JPEG " ; // save the image in the output stream Image.Save (context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); Image.Dispose (); } public BOOL the IsReusable { GET { return to false ; } } } }
Arranged at both ends of the code as follows
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1126400000" />
</requestFiltering>
</security>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="IHttpHandler" verb="GET,POST" path="LokARX.cc" type="SoonnetWebSite.Web_Data.Lok_ARequestX, SoonnetWebSite" />
<add name="IHttpHandler2" verb="GET" path="LokIF.cc" type="SoonnetWebSite.Web_Data.Lok_Interface, SoonnetWebSite" />
<add name="Handler1" verb="*" path="*.jpg" type="SoonnetWebSite.Handler1, SoonnetWebSite" />
</handlers>
<modules>
<add name="Handler2" type="SoonnetWebSite.Handler2,SoonnetWebSite" />
</modules>
</system.webServer>
Found a problem with the machine test nodes IIS configuration is not the same. Layout line use
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1126400000" />
</requestFiltering>
</security>
<validation validateIntegratedModeConfiguration="false" />
<HttpHandlers>
<add name="IHttpHandler" verb="GET,POST" path="LokARX.cc" type="SoonnetWebSite.Web_Data.Lok_ARequestX, SoonnetWebSite" />
<add name="IHttpHandler2" verb="GET" path="LokIF.cc" type="SoonnetWebSite.Web_Data.Lok_Interface, SoonnetWebSite" />
<add name="Handler1" verb="*" path="*.jpg" type="SoonnetWebSite.Handler1, SoonnetWebSite" />
</HttpHandlers>
<HttpModules>
<add name="Handler2" type="SoonnetWebSite.Handler2,SoonnetWebSite" />
</HttpModules>
</system.webServer>
Configuring more than a front http
Because IIS is a classic model with an integrated model of relations,
Reference link: https: //blog.csdn.net/hongwei_23/article/details/44300923
http https turn reference link: https: //blog.csdn.net/suxuelian/article/details/80103514