The little Thing before MVC series (1) entering the CLR
MVC before the point of the series, is the author in the early 2012 to read the MVC3 source when the collation, the main story is from the HTTP request to enter the Mvchandler before the content, including the original, translation, reprint, collation and other types of articles, of course, also refer to the blog Park a number of articles, Daniel Thank you for this, there is time to put it out, hope to be useful to everyone.
Main content
This article explains how the server takes the HTTP request request and how it enters the. Net CLR for further action.
As we all know, IIS must accept the request before it has a chance to enter the CLR, but is not aware of how requests are routed from the Web server to the ASP. Because of the different versions of IIS, the way in which the CLR is entered may vary, and this section will explain the way in which the three versions of IIS5/6/7 are entered, and the understanding of these underlying mechanisms allows us to have a deeper understanding of ASP.
IIS 5
the ASP. NET Request Processing Process
The IIS5 core feature is that IIS is allowed on a process called InetInfo.exe, so both the ASPX page and the HTML page are processed through this process, where the ASPX page extension is mapped to the ASPNET ISAPI. DLL, so if the page is ASPX, the ASPNET ISAPI. DLL creates aspnet_wp this worker Process and loads the CLR at initialization time, so this is a managed environment.
The points to note are:
- The same server can only run one aspnet_wp process, which means that all ASP. NET Web application are in the same worker process, but it does not mean that they share the same context and database, ASP. NET has an AppDomain concept, each site or virtual directory corresponds to a separate AppDomain, each AppDomain is isolated, has its own separate context context, so security is no problem, So our conclusion is that the ASP is to continue the AppDomain, not process-based.
- The ASP. NET ISAPI is not only responsible for creating the aspnet_wp Worker process, but also for monitoring the process, if the aspnet_wp performance is detected to a lower limit, the ASP. NET ISAPI will end the process, When the request comes in, the ASP. NET ISAPI will recreate the new aspnet_wp Worker Process.
- Because IIS and application run in their respective processes, communication between them must adopt a specific communication mechanism. Due to the communication between the different processes of the machine (local interprocess communications), in performance, they use a communication mechanism based on named pipe. The communication between the ASP. NET ISAPI and worker process is implemented through a set of pipes between them. Also in performance, the ASP. NET ISAPI asynchronously passes the request to worker process and obtains Response, but the worker process is synchronized to the ASP. Some Server-based variables.
IIS 6
the ASP. NET Request Processing Process
IIS6 and IIS5 have 3 very different places: Accept requests (HTTP. sys), application pools (application pool), W3wp.exe Worker Process.
In IIS5, the InetInfo.exe attachment listens and processes requests (request), but in IIS6, the server receives the request via a new component, HTTP. sys.
When HTTP. SYS receives the request, it will see which application pool the application based on the request belongs to, based on Metabase in IIS, and if the application pool does not exist, it is created. Otherwise, the request is sent directly to the queue corresponding to the application Pool.
Each application Pool corresponds to a worker Process:w3wp.exe. The mapping of application Pool and worker process are maintained in IIS Metabase. The WAS (Web Administrative service) passes the request that exists in a application Pool queue to the corresponding worker process (if not, based on such a mapping). Create a process like this). When the worker process is initialized, the ASP. Isapi,asp.net ISAPI loads the CLR.
Note: One difference between IIS5 and IIS6 is that the ASP. NET ISAPI in IIS5 creates the aspnet_wp Worker Process, which then loads the CLR, but in IIS6 is w3wp after the application pool's map relationship runs To load the ASP. NET ISAPI and then load the CLR.
IIS 7
the ASP. NET Request Processing Process
Step 1 to 6, is the processing application start, after the start, you do not need to go this step again, the 8 steps are as follows:
- The HTTP. SYS listener intercepts the client request to begin processing.
- HTTP. Sys contacted was for information about the configuration information.
- was requested configuration information from the configuration Store center. ApplicationHost.config.
- The WWW service receives configuration information, configuration information such as application pool configuration information, site configuration information, and so on.
- The WWW service uses configuration information to configure the HTTP. SYS processing policy.
- Was opened w3wp Worker Process for the application pool (application pool) corresponding to this request.
- After the w3wp Worker process is processed, the response is returned to HTTP. Sys.
- The client receives the response content.
What if the W3WP.exe process is done?? Depending on the application pool managed pipeline mode of IIS 7, IIS7 currently has 2 modes: Classic mode and Integrated mode. The two modes of processing are not the same, see the following differences:
IIS7 Classic mode:
IIS7 's Classic mode and IIS6 are handled the same way, after the user sends the HTTP request request, IIS will process, IIS will filter according to the HTTP request type, if the HTML static Web page is handled by IIS itself, if not, Assign to the respective IIS ISAPI extension for content types that are specific to the requirements, and if the required content type is ASP, assign to the IIS ISAPI extension that is responsible for processing ASP. Isapi.dll, and then into the CLR.
IIS7 Integrated mode:
IIS7 Integration mode is a great improvement that has preloaded the CLR (not on the IIS version before relying on the Aspnet_ispai. DLL), which means that all HTTP request requests are processed by ASP (including HTML, PHP, etc.), and because many of the features of ASP. asp, PHP, or static HTML Web pages, etc. You can also use ASP. NET 2.0 features such as the Forms authentication (forms authentication) or output cache (outputs caching) (but you need to modify the settings for IIS 7), as well as IIS 7 allows you to develop and join your own ASP. module, it is easier for ASP. NET Web page developers to expand the functionality of IIS 7 and Web site applications, and even to write programs that manage IIS 7 (for example, to program IIS 7 to build Web sites or virtual directories).
Summarize:
The way that different IIS versions enter the CLR is not the same as when the maximum change between IIS versions is:
- IIS5 to IIS6 improvements, mainly HTTP. sys.
- IIS6 to IIS7 improvements, mainly ISAPI improvements.
tip: Starting with the next section, we'll go to Microsoft. NET4 and MVC3 source for in-depth analysis, so before you continue to the following chapters, please download these source code, the address is as follows (only need to download. NET4 and MVC3, others not required):
http://referencesource.microsoft.com/
References:
Http://dotnetslackers.com/articles/iis/ASPNETInternalsIISAndTheProcessModel.aspx
Http://dotnetslackers.com/articles/iis/ASPNETInternalsIISAndTheProcessModel2.aspx
Http://www.cnblogs.com/riccc/archive/2007/07/08/asp-net-internals-iis-and-the-process-model.html
http://learn.iis.net/page.aspx/243/aspnet-integration-with-iis/
Http://learn.iis.net/page.aspx/101/introduction-to-iis-architecture/
Http://www.west-wind.com/presentations/howaspnetworks/howaspnetworks.asp
Http://www.cnblogs.com/zhaoyang/archive/2011/11/16/2251200.html
Http://www.dotnetfunda.com/articles/article821-beginners-guide-how-iis-process-aspnet-request.aspx
Synchronization and recommendations
This article has been synchronized to the directory index: Thelittle Thing before MVC series
MVC before the point of the series of articles, including the original, translation, reprint and other types of articles, if it is useful to you, please recommend supporting a, to the power of the uncle writing.
Original link This article by Bean John Blog Backup expert remote One click release
The little Thing before MVC series (1) into the CLR (reprinted)