Take notes on learning ASP. net mvc frameworks-IIS/ASP. NET pipelines (1), mvc-iis
IIS/ASP. NET Pipelines
ASP. net mvc is a Web application framework based on the MVC pattern on the ASP. NET platform. a deep understanding of ASP. net mvc requires a deep understanding of ASP. NET pipeline design. Since most ASP. NET Web applications are hosted on IIS, the following section describes how to process the Web requests of the three major IIS versions.
1.3.1 IIS 5.x and ASP. NET
IIS 5.xis running in inetinfo.exe. The process host a Windows Service named World WideWeb Publishing Service (W3SVC. W3SVC monitors, activates, and manages HTTP requests, loads configurations (loads related configuration information from Metabase), and so on.
When an HTTP request is detected, the iis request is a static resource (such as .html?.img=.txt and. xml) or a dynamic resource. For the former, IIS will directly return the file content to the client, for dynamic resources (such. aspx ,. asp ,. (php, etc.), the corresponding ISAPI Dynamic Link Library (DLL) is found from the Script Map of IIS through the extension ).
ISAPI (Internet Server Application Programming Interface) is a set of local (Native) Win32API, which is the link between IIS and other dynamic Web applications or platforms. ISAPI is defined in a dynamic link library (DLL) file. The DLL file name corresponding to ASP. net isapi is called aspnet_isapi.dll. ISAPI supports ISAPI extension and ISAPI filtering. The former is an interface that truly processes HTTP requests, and the latter can view, modify, forward, or reject requests before they are actually processed, for example, IIS can use ISAPI to filter requests for verification.
If the request is based on ASP.. NET resource type, such. aspx ,. asmx ,. svc, etc. aspnet_isapi.dll will be loaded, ASP. net isapi will then create ASP. NET (if the process has not been started ). For iis5.x, the process is aspnet.exe. The IIS process communicates with the working process through the naming pipeline.
During workflow initialization, the. NET Runtime (CLR) is loaded to build a hosted environment. For the first request of a Web application, CLR will create an application domain for it. In the application domain, HTTP Runtime is loaded and used to create corresponding applications. All Web applications hosted on IIS 5.xare run in different application domains in the same process (job process aspnet.exe.
1.3.2IIS6.0 and ASP. NET
Based on the previous introduction, we can see that IIS5.x has at least two shortcomings.
1.isapi is redirected to the interinfo.exe process, which is a typical cross-process communication mode between it and the working process. Although named pipelines are used, they still bring performance bottlenecks.
2. all ASP.. NET applications run in different application domains of the same process. Isolation Based on application domains cannot fundamentally solve the impact of one application on another, in more cases, we need different Web applications to run in different processes.
To solve the first problem, IIS6.0 directly loads the ISAPI Dynamic Link Library to the working process. To solve the second problem, the application pool mechanism is introduced in IIS6.0. We can create an application pool for a Web application, and no application pool corresponds to an independent workflow (w3wp.exe). Therefore, Web applications running in different application pools provide process-level isolation mechanisms.
In addition to the above two improvements, IIS6.0 also has some other commendable points, the most important of which is the creation of an HTTP listener named HTTP. SYS. HTTP. SYS runs in the Window kernel mode as a driver. It is part of the WindowTCP/IP network subsystem. In terms of structure, it is a network driver over TCP.
Strictly speaking, HTTP. SYS is no longer in the scope of IIS. Therefore, the configuration information of HTTP. SYS is not stored in the Metabase of IIS, but is defined in the registry. HTTP. SYS can bring the following benefits.
1. continuous listening. Because HTTP. SYS is a network driver and is always running, it can respond to users' HTTP requests in a timely manner.
2. Better stability. HTTP. SYS runs in the operating system kernel mode and does not execute any user code. Therefore, it is not affected by Web applications, working processes, and IIS processes.
3. data cache in kernel mode. If a resource is frequently requested, HTTP. SYS caches the response content, and the cached content can directly respond to subsequent requests. Because this is a cache based on the kernel mode, there is no switch between the kernel mode and the user mode, and the response speed will be greatly improved.
When listening for HTTP requests, HTTP. SYS distributes the request to W3SVC. The latter parses the request URL and obtains the target application based on the ing relationship between the URL obtained from Metabase and the Web application, then obtain the application process pool or worker process that the target application runs. If the worker process does not exist (not created or recycled), it creates a new worker process for the request. During the initialization process, the corresponding ISAP dynamic link library is loaded. for ASP. NET applications, the ISAPI. dll to be loaded is aspnet_isapi.dll. ASP. net isapi is responsible for CLR loading, application domain creation, and Web application initialization.
In the next chapter, we will explain IIS7.0 and ASP. NET.