After a visitor enters a URL in the browser and links it to IIS, IIS starts the corresponding IIS extension program to process this requirement based on the file extension required by the visitor, the corresponding table of the file extension can be modified through the Internet administrator program provided by IIS.
We select PageHandlerFactory-ISAPI-2.0, right-click, and select Edit to see the following page:
It is known that the extension. the ISAPI extension corresponding to the aspx file is aspnet_isapi.dll, which is located in. in the installation directory of Net Framework, the default value is % WinDir % \ Microsoft. net \ framework \ vxxxx. ASP. NET work process (WP). This file is also located in the. NET Framework installation directory. When aspnet_isapi.dll receives a visitor request from IIS, it passes the request through named
The pipe protocol is forwarded to the running WP program. At this time, WP will work out the required virtual directory information to decide to create a new appdomain object or use the previously created appdomain object to handle this requirement, in theory, each virtual directory corresponds to an appdomain object. However, when the system memory is insufficient, WP will choose whether to release idle appdomain objects as the system memory consumption degrades, allows the system to accommodate a large number of visitors. When WP finds that the virtual directory where the file is located does not have the corresponding appdomain object, WP will create a new appdomain object and load the assemblys and files required by visitors during Asp.net execution, that is. the aspx file shows the process.
Many techniques are implied in the action of loading. aspx files (a representative figure is found online), as shown in:
After WP receives a request from aspnet_isapi.dll, it will forward the request to the isapiruntime object in the applicatioin domain corresponding to the virtual directory. The main function of this object is to resolve the information in the ISAPI package and transfer it to the httpruntime object, after the necessary information is obtained, the isapiruntime object then calls httpruntime. the processrequest function is used to process user requirements. An httpcontext object is created in this function, and the httpruntime object fills in access information from the isapiruntime object. In terms of the overall structure, the httpruntime object manages the httpcontext and cache objects, while the httpcontext object manages an httpsession object. Each visitor request corresponds to an httpcontext object, therefore, each visitor naturally has an independent httpsession object. After an httpcontext object is created, an httpapplication object is created through the httpapplicationfactory object. When the httpruntime object requests an httpapplication object from the httpapplicationfactory object, the httpapplicationfactory object first interprets the global. the asax file, and then load the application in the virtual directory
Assembly (Global. dll), then combine the two to create a ghost application class, finally compile this class, get the object instance, and return to the httpruntime object. This object instance is the httpapplication object. The action of interpreting and compiling the. asax file only occurs when the virtual directory processes user requirements for the first time, or global. asax and Global. dll are modified after the previous execution. After an httpapplication object instance is obtained, the httpruntime object calls the httpapplication. processrequest function, which transfers the execution permission to the corresponding httphandler object. During the initialization of the httpapplication object, the relevant httpmodules will be loaded. httpmodules refers to the applicatioin-level modules, such as session and authenticaiton modules. Each httpmodule must implement the ihttpmodule interface, the following code is a prototype of the ihttpmodule interface.
namespace System.Web{ public interface IHttpModule { void init(HttpApplication context); void Dispose(); }}
The init function is called when the httpapplication object loads the module. Generally, the event handler function is usually attached to the event provided by the httpapplication object, in this way, the master privilege is obtained when these times occur. For example, the sessionstate module intercepts httpapplication. beginrequest, endrequest, and other events to process the session. The dispose function is called when the httpmodule is released. The program code for memory release is usually written here. Generally, there are few cases where designers write httpmodule, most of which are used to provide additional authentication or service features. Most of the actions described in this article are not intervened by the designers, and it is difficult to know the actual operation mode. What is closely related to the designers is the ghost.
The creation process of applicatioin class is the key to how Asp.net combines the compilation and interpretation technologies.