The ASP.NET runtime object generation process and the HTTPHANDLER and HTTPMODULE process.

xiaoxiao2021-03-06  175

Now narrow the final process, when ASP.NET acquires an ASPX system request, what happened after the control is obtained.

First, it detects whether there is a runtime process that is responsible for processing the ASP.NET content (IIS5 is a w3wp.exe, if you don't create one, then transfer the control to this process (that is the function pointer Jump operation).

When this process is connected to the control, check if there is an instance of the HTTPRuntime class in the application domain of this site in the process, and does not create a new instance. An instance of multiple HTTPRuntime classes in a server, because the IIS of a server may create multiple sites, while each site may create a new multiple virtual directory. However, each site can only create an instance of an HTTPRuntime class to prevent excessive resource resources.

HttPruntime is the foundation of the ASP.NET runtime program. He is responsible for controlling an ASP.NET request for each site / virtual directory (note is not HTTP request), but it is not responsible for processing requests. The Httruntime object is controlled by the HTTPApplicationFactory object, which is a factory object, responsible for generating classes.

The HTTPApplicationFactory class is responsible for controling an object pool, the object inside the object pool is the HttPApplication object we often use. First, HTTPApplicationFactory is responsible for handling the Global.ascx program and triggers the Application_onstart event, then get an HttPApplication instance from the pool and put the request to be processed into the instance. If there is no available object, create a new HTTPApplication object. To create an HttPApplication object, you need to complete the compilation of the Global.asax application file first. The httpapplication will then start processing the request and can only process new requests after completing this request. If a new request from the same resource is received, it is handled by other objects in the pool. That is to say, if a site has many users, multiple requests of multiple users will be processed by different httpApplication.

The application object allows all registered HTTP modules to prepare the request (note that this is httpmodule to start working) and identify the type of handler that best suits the process. This is done by looking for the expansion of the requesting URL and the information in the configuration file.

So, the final processing ASP.NET page is a class instance named httpapplication. According to the above steps: When HTTPRuntime launches HTTPAPPLICATIONFACTORY, the first startup is the ASP.NET's own event preprocessor Global.ascx, and then it is turned to httpapplication.

How does ASPX's processing definition system know? The answer is obtained from the Machie.config configuration file. This file defines the handler of all .aspx, .ashx, .asmx, .ascx and other files.

Conclusion: Process Process ISAPI -> ASPNET_WP.EXE / W3WP.EXE -> HTTPRUNTIME -> HTTPApplicationFactory -> HTTPApplication -> Content HTML

So, can we customize the process processing? Yes, the method is the role of the owner's HTTPModule and HTTPHANDLE (HTTP processor). Httpmodule is a custom version of the Event handler running by HttPApplicationFactory before HTTPApplicationFactory, which allows you to write a class inherited to the ihttpmodule interface instead of ASP.NET to handle an ASPX page, or even all ASPX Pages, not help you with ASP.NET. HTTPHANDALER is the alternative version of HTTPApplication after processing after Global.ascx, that is, you can write a class, inherit httphandler, instead of HTTPApplication to handle an ASPX, or all ASPX, you can come with your heart Process any content of ASPX. However, all content processing must have you write code to handle it, it is very convenient.

转载请注明原文地址:https://www.9cbs.com/read-128318.html

New Post(0)