One of ASP. NET process models: IIS and ASP. net isapi [zz]

Source: Internet
Author: User
Tags metabase

PS: The author wrote it clearly. It is worth taking a closer look and learning about the underlying mechanism of Asp.net.
A friend asked me on MSN a few days ago, "what is the whole process from ASP. NET receiving HTTP request to generating response ?" I think this problem involves IIS and ASP. netasp. net runtime processing model is not clear in just a few words, so I decided to write this article to introduce IIS and ASP. net runtime Process Model article, talk about a superficial understanding of this, if there is anything wrong, I hope you can correct it in time.

This article is divided into two parts. The first part is about two different versions of IIS-IIS 5.x and IIS 6 (although IIS 7 has been release for a long time, in addition, the two versions have undergone great changes. Due to my lack of in-depth understanding of IIS 7, I will not introduce them here, but I will add this content later) processing Model: How does IIS listen for HTTP requests from outside, how does it distribute requests for different resources to different ISAPI extension based on ISAPI extension ing, and based on ASP. net resource ASP. net ISAPI how to pass a request to ASP.. Net runtime environment. The second part focuses on the processing of incoming HTTP requests in a hosted ASP. NET runtime environment. Let's take a look at the processing process of IIS 5.x and IIS 6.

1.I. IIS 5. x Based Process Model

A notable feature of IIS 5.x is the separation of Web server and real ASP. NET application. Iisworking as Web server is running in a process named inetinfo.exe. inetinfo.exe is a native executive, not a hosted program, but our real ASP. NET application runs on a worker process called aspnet_wp. It loads CLR during initialization, so it is a managed environment. Let's take a look at the creation of aspnet_wp, how aspnet_wpcommunicates with inetinfo.exe, and how to import requests to ASP. NET rutime pipeline in aspnet_wp.

We create a virtual directory to host the resources under IIS. In principle, we can access all resources placed under the virtual directory through IIS. This file only contains some static resource files, such as HTML files, CSS files, and JS files that require dynamic execution, such as aspx and asmx. We can also mount remoting and WCF Service host to IIS. For these static files, IIS directly extracts the corresponding files and returns them to the client as HTTP response. However, for these files that need further processing, IIS must pass the request to the corresponding handler. After the handler is executed, the final HTTP response is returned to the client through IIS. For IIS, these handlers are embodied through ISAPI extension. For ASP. NET-based resources, the corresponding ISAPI extension is ASP. net isapi, which is carried by an aspnet_isapi.dll. The IIS metadata database maintains a data table called ISAPI extension mapping, which is responsible for copying different types of resources to the corresponding ISAPI extension.

For example, we show how IIS 5.x processes an HTTP request based on ASP. NET Resource (taking aspx as an example. First, the user requests An ASPX page through browser, Brower to the IIS for the Web server, that is, the target host. After reading this article, iisruns in a process called inetinfo.exe. inetinfo.exe is a native executive, not a hosted program. IIS analyzes the extension of the target resource file for the request (here it is aspx). Through ISAPI extension mapping, it obtains that the corresponding ISPAI is ASP. net isapi, and loads aspnet_isapi.dll. So far, the request is processed by ASP. net isapi. ASP. net isapiwill create a worker process(called as aspnet_wp.exe (if the process does not exist, the CLR will be loaded during the initialization of aspnet_wp.exe, thus being ASP.. NET application creates a managed runtime environment. During CLR initialization, two important DLL values are loaded: appmanagerappdomainfactory and isapiruntime. Create an application domain for the application through the create method of appmanagerappdomainfactory; process the request through the processrequest of isapiruntime, and then drag the process to ASP. net HTTP runtime pipeline category, Asp. net HTTP runtime pipeline is a relatively complex process for processing HTTP requests. The relevant introduction documents are placed in the next part of this article. Here we can regard it as a black box, which takes over the request and finally generates HTML.

This is basically the entire processing process, which is very simple. However, there are several points that need to be pointed out here.

1. first, only one aspnet_wp process can be run on the same host at a time, and each ASP. NET application corresponds to an application domain, that is to say, each application runs in the same worker process. Application Isolation is based on application domain rather than process.

2. second, Asp. net ISAPI is not only responsible for creating the aspnet_wp worker process, but also responsible for monitoring the process. If the performance of aspnet_wp is detected to a lower limit, Asp. net ISAPI is responsible for killing the process. When aspnet_wp is terminated, subsequent requests will cause ASP. net isapi to re-create a new aspnet_wp worker process.

3. Finally, since IIS and application are running in their respective processes, the communication between them must adopt a specific communication mechanism. Essentially, the communication between the Inetinfo process of IIS and the worker process is the communication between different processes of the same machine (local interprocess communications), which is considered for performance, they use Named Pipe-based communication mechanisms. Communication between ASP. net isapi and worker process is implemented through a set of pipe between them. ASP. net ISAPI uploads the request to the worker process asynchronously and obtains the response. However, the worker process is synchronized to ASP. net ISAPI to obtain some server-based variables.

2. II,IIS 6 Based Process Model

Reliability and performance are never the same theme as we are engaged in software development. As a host based on HTTP application IIS, these two aspects are particularly important. From the evolution of IIS 5.x to IIS 6, it is not difficult to see that the improvements made by IIS 6 in the previous version are also based on these two aspects. Before introducing the processing model of IIS 6, let's look at the defects of IIS 5.x:

1. first of all, from the performance perspective, IIS and application run in different processes, although they use Named Pipe-based Asynchronous communication methods, however, the impact of inter-process-based communication on performance cannot be fundamentally solved.

2. secondly, in terms of reliability, only one worker process can be run on one machine, and each application runs in the same process. Although application domain-based isolation can provide a certain degree of reliability, however, once a process crashes, all applications will be affected. Therefore, we sometimes need to provide process-based isolation.

Based on the Reliability Improvement, IIS 6 introduces the application pool. As the name suggests, application pool is an application container. in IIS 6, we can create several application pools. When creating a web application, we specify an established application pool for it. At runtime, an application corresponds to a worker process: w3wp.exe. That is to say, different from the previous version of IIS, for IIS 6, multiple worker processes can be run on the same machine at the same time, and each application domain in each worker process corresponds to one application. In this way, not only application domain-level isolation can be provided between applications, but you can also place different applications in different application pools to implement process-level isolation. For some important applications of host, this method can provide good reliability.

In terms of performance, IIS 5.xlistens to requests through inetinfo.exe and distributes requests to work process. In other words, in IIS 5. in user mode, request listening and distribution are performed. In IIS 6, this kind of work is transplanted to the kernel mode. All of this is done through a new component: HTTP. SYS.

Note:To prevent users' applications from accessing or modifying critical operating system data, Windows provides two processor access modes: user mode and kernel mode ). Generally, the user program runs in user mode, while the operating system code runs in kernel mode. The kernel mode code allows access to all system memory and all CPU commands. For details about the user mode and kernel mode and some underlying Windows systems, we recommend that you take a look at Microsoft Windows internal four edition, authored by Mark E. russinovich & David A. Solomon.

The entire process of IIS 6 is basically demonstrated. In user mode, HTTP. sys receives an HTTP request based on aspx, And then it checks which application pool the request-based application belongs to based on metabase in IIS. If the application pool does not exist, it is created. Otherwise, the request is directly sent to the queue of the corresponding application pool. As I have mentioned above, each application pool corresponds to a worker process: w3wp.exe, which is undoubtedly running in user mode. The application pool and worker process mapping are maintained in IIS metabase. Based on such a ing, the was (Web administrative service) transmits requests that exist in an application pool queue to the corresponding Worker Process (if not, such a process is created ). When the worker process is initialized, ASP. net isapi and ASP. net isapi are loaded to load CLR. The final process is related to IIS 5. X is the same: Create an application domain for the application through the create method of appmanagerappdomainfactory; process the request through the processrequest of isapiruntime, and then enter the process to ASP. net HTTP runtime pipeline.

Here is an introduction to the IIS Process Model section. In the next section, I will introduce ASP. NET HTTP runtime pipeline.

Reference:
The ASP. net http Runtime
ASP. NET internals-IIS and the process model
ASP. NET internals-the bridge between ISAPI and application domains
Microsoft Windows internals, Fourth Edition: Microsoft Windows Server 2003, Windows XP, and Windows 2000

ASP. NET Process Model
[Original] One of ASP. NET process models: IIS and ASP. NET ISAPI
[Original] ASP. NET Process Model 2: ASP. net http runtime pipeline-Part I
[Original] ASP. NET Process Model II: ASP. net http runtime pipeline-Part II

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.