Opening : Asp. Net is a dynamic web development technology, in the long history of the development of WebForm once became synonymous with the ASP, and the advent of ASP, which makes this technology more vibrant. However, whether ASP . NET WebForm or ASP. Net-MVC is mostly the same on the request processing mechanism, except that the processing events on the request processing pipeline do different things, so the title of this article does not distinguish between ASP . WebForm and ASP. NET MVC, but will be distinguished in the following introduction. In addition, this article focuses on the IIS Classic mode and does not discuss the integration mode (IIS7 after integration mode, without loading the external aspnet_isapi.dll components).
(1) Part 1: Prelude
(2) Part 2: Core
(3) Part 3: Piping
(4) Part 4:webform page life cycle
(5) Part 5:mvc page sound life cycle
First, when a request arrives, the ① client sends a request to the server side
② an HTTP request corresponds to an HTTP message
③http.sys component capture request, the most basic processing of the message
HTTP. SYS is an operating system core component (in kernel mode)that resides in Windows Server and Windows XP SP2, allowing any application to communicate with the HTTP protocol through the interfaces it provides.
About kernel mode and user mode:
In the Windows Server operating system, a process can run either in kernel mode or in user mode. If a process runs in kernel mode, the process can access all hardware and system data, and if a process runs in user mode, the process does not have direct access to the hardware and restricts access to system data. There are 0~3 four privileged levels in the Intel processor architecture, kernel mode running at level 0, and user mode running at level 3. By running HTTP. sys in kernel mode, the listener can access the TCP/IP protocol stack directly, but can be located outside the WWW service so that it is not affected by code flaws in the application and does not cause problems due to application crashes.
④ responds directly if the request has cached content
HTTP. SYS component is an important function of it is that it has a buffer, will be the response of the recent processing into the buffer, if the request for this content, will be obtained from the buffer cache content and response, improve the response speed. Also, static content is now cached in kernel mode, which makes the service more responsive .
Second, determine whether dynamic resources ①iis first determine whether the content of the request is a static resource?
IIS first determines whether the request is a static resource and, if so, directly responds to the request with resources such as the requested html/css/js/jpg/gif/png in the file system.
② If it is a dynamic resource, which extension is the first lookup for processing?
IIS itself does not handle dynamic resource requests, and it finds out which Extender should handle this request based on the requested resource type to a known handler mapping . In IIS, requests for ASP. NET are typically made by the Aspnet_isapi.dll component to load and handle specific requests. With an ISAPI-based extension extension, the IIS server can determine which ISAPI extender should handle client requests based on the resource extension requested by the client, and then forward the request to the appropriate ISAPI extender.
About IIS Server Extensions:
Because the IIS server introduces an open ISAPI interface standard at design time, it is highly scalable. You can flexibly support different types of ASP. NET applications with the same core components.
About ISAPI:
ISAPI (Server application Programming Interface), which provides developers with a powerful programmability to extend the functionality of IIS by developing ISAPI extensions for different types of Web applications according to standard interfaces, enabling IIS to handle different types of client requests. IIS Manager provides application configuration features that allow you to configure different ISAPI extenders for different client requests. ISAPI extenders typically exist as DLLs and can be loaded and invoked by IIS.
A city magical entrance ① the so-called worker process (worker processes)
We have just introduced the process steps of IIS in general, but in fact, the processing of dynamic resources by IIS first through a worker process to load the specific processing component DLL. In IIS 6.0, for example, if IIS determines that it cannot handle ASP. NET requests, the Aspnet_isapi.dll is loaded by the worker process maintained by W3WP.exe.
②.net Loading of the runtime
If the Web application is loaded for the first time, the. NET runtime is first loaded by Aspnet_isapi.dll, primarily the. NET Framework on the calling server to create the CLR runtime. An IIS worker process has an application pool that can host more than one application domain appdomain.
About application Pools:
An application pool is a container that can be viewed as the memory that is allocated to a dynamic Web site by a load computer. If the memory is water, then the application pool is a fish tank, dynamic website is goldfish in the aquarium. Multiple dynamic sites can exist in the same application pool, that is, you can put more than one goldfish in the aquarium. Of course, if more goldfish, fish tank space is limited, goldfish will scramble for space, not very strong fish tank may break, all goldfish will be affected. That is, the dynamic site is more, memory is not enough, may cause a memory-level overflow vulnerability, affecting all the dynamic sites on that application pool.
About application domains:
Use. NET is an executable program that is not directly hosted in the process, but is hosted in the application domain (AppDomain). The application domain is. NET introduces a new concept, which is less than the resources consumed by the process and can be seen as a lightweight process.
③ Loading of application domains
After the. NET runtime is created, the application domain AppDomain is created through the application domain factory appdomainfactory. After the AppDomain is created, the request is forwarded to the Isapiruntime object in the AppDomain, and then the ProcessRequest () method of the Isapiruntime object is called for processing.
The isapiruntme.processrequest () method is the first entry into ASP. The core processing part of NET is just beginning. This is what I call the prelude, because it is in the core processing part of the ASP, the HTTP request is passed to the Isapiruntime object step-by-step, after we continue to explore the request processing mechanism of ASP, this is the end today!
Iv. Overview of the Prelude process
Resources
(1) Darren Ji, 19 key steps of the ASP. NET MVC request processing Pipeline declaration cycle: http://www.cnblogs.com/darrenji/p/3795661.html
(2) JACKYXM, "HTTP." SYS Detailed: http://www.cnblogs.com/yxmx/articles/1652128.html
(3) Wood Wancheng Master, ASP. NET that little-known thing: http://www.cnblogs.com/OceanEyes/archive/2012/08/13/aspnetEssential-1.html
(4) Tony He, ASP. NET request processing mechanism: http://www.cnblogs.com/cilence/archive/2012/05/28/2520712.html
Asp. NET request processing mechanism preliminary exploration tour-Part 1 Prelude