HTTP request processing process of asp.net
(1 ),The ghost process is intercepted and then transferred to the aspnet_isapi.dll process. Then, it is transmitted to the aspnet_wp.exe process through the Http pipelinepipeline. Then it is sent to the HttpRunTime processing center of the. net framework and sent to the user's browser after processing.
(2 ),After an http request is sent to HttpRuntime, the request will be sent to a container called HttpApplication Factory, the container will provide an HttpApplication instance to process the passed http requests, and then the Http requests will go to the following containers in sequence: HttpModule --> HttpHandler Factory --> HttpHandler. After the HttpHandler's ProcessRequest method in the system is processed, the entire Http Request is processed and the client obtains the corresponding information.
(3)Complete http request processing process in asp.net framework:
HttpRequest --> inetinfo.exe-> Pipeline --> Http Pipeline --> ASPNET_WP.EXE --> HttpRuntime --> HttpApplication Factory --> HttpApplication --> HttpModule --> HttpHandler Factory --> HttpHandler. processRequest ()
(4)If you want to intercept an httpRequest in the middle and perform some processing on your own, you should implement this internally during the HttpRuntime runtime, specifically in the HttpModule container.
How HttpModule works
Monitors HttpRequest and adds or filters out some content for HttpRequest.That is, when an HTTP request arrives at HttpModule, the entire ASP. the. NET Framework system has not processed this HTTP request. That is to say, HttpModule is the "Only Way" for an HTTP request ", therefore, some required information can be appended to the HTTP request information before the HTTP request is passed to the real request processing center (HttpHandler, you can also perform some additional work on the intercepted HTTP request information, or simply terminate the HTTP request that meets certain conditions in some cases, so as to act as a Filter.
HttpModule implements the IHttpModule interface. We can customize the classes that implement this interface to replace HttpModule.
Compile your own HttpModule
To implement HttpModule, you must implement the IHttpModule interface. The following is an analysis of the IHttpModule interface:
2. Call the Init () method of Modul when creating a Module instance.
3. register the events exposed by HttpApplication that you want to respond to in the Init () method. (Only simple registration of methods is required. The actual method needs to be written separately ).
4. HttpApplication triggers various events in its application cycle.
5. When an event is triggered, call the method that the Module has registered in its Init () method.
+ ==+ = Context_BeginRequest (= context_EndRequest (=
In our own http module, assume that the class is named ModuleDemo, which is located in the Learning namespace and the Assembly name is Learning. We only need to copy the Learning to the Bin directory, and in the web. config file system. create an httpModules node under a web node: