One of the ASP.net Process model IIS and asp.net isapi_win servers

Source: Internet
Author: User
Tags http request
A few days ago there was a friend inMsnAsk Me "asp.netFrom the initial receipt ofHttp RequestTo the final buildResponseWhat is the whole process? "I think this question involvesIisAndASP.NETASP.NET RuntimeThe problem of the processing model is not words can be made clear, so decided to write such an introductionIisAndasp.net Runtime Process ModelArticle, to talk about my superficial understanding of this, if there is anything wrong, I hope you correct.

This article is generally divided into two parts, the first part I will talk about IIS two different versions-iis 5.x and IIS 6(although IIS 7 has been release for a long time, and compared to the first two versions have undergone a very large change, Because I do not have the in-depth understanding of IIS 7, so here is no longer introduced, but I will add to this aspect of the processing model: How IIS listens to the HTTP request from the outside, how to According to the ISAPI Extension Mapping distributes requests for different Resource to different ISAPI Extension, Resource ISAPI based on asp.net asp.net how the request passed to ASP.net Runtime environment. The second section focuses on the process of handling incoming HTTP request in a managed asp.net Runtime environment . Let's take a look at the process of IIS 5.x and IIS 6 .

1. One, IIS 5.x based Process Model

A notable feature of

IIS 5.x is the separation of Web Server and True asp.net application . As IIS for Web Server runs on a process named InetInfo.exe , InetInfo.exe is a native Executive , not a managed program , and our real asp.net application is run on a worker process called aspnet_wp , which loads the CLR when the process initializes , So this is a hosted environment. We'll talk about aspnet_wp How to create, aspnet_wp and InetInfo.exe How to communicate, and simply introduce in aspnet_wp , how to apply the request Import asp.net rutime Pipeline .

We can, in principle, access all resource under the virtual directory through IIS by creating the virtual directory to host the resources to IIS . This only contains some static resource files, such as pictures, pure HTML files, CSS , JS and so on, but also contains some files that need to be executed dynamically, such as Aspx , asmx , and so on, we can also remoting and WCF Service Host to IIS . For these static files, IIS extracts the corresponding files directly as HTTP Response to the client , but for these dynamically executed files that require further processing, IIS must request The is further passed to the corresponding handler, which completes the execution of the pending program and obtains the final HTTP Response through IIS to return to the client . For IIS , these handlers are represented through ISAPI Extension . For resource based on ASP.net , its corresponding ISAPI Extension is asp.net ISAPI , hosted by a aspnet_isapi.dll . The IIS metadata database maintains a data table called the ISAPI Extension Mapping , which is responsible for mapping different types of resource to the corresponding ISAPI Extension . /span>



On the image we've shownIIS 5.xHow to deal with one based onasp.net Resource(InaspxAs an example) ofHttp Requestof the general process. First, the user passesBrowserRequest aASPX page,BrowerToWeb Server, which is the target host'sIis。 In the above we mentioned thatIisRun in a calledInetInfo.exeIn the process,InetInfo.exeis aNative Executive, not a managed program.Iis Parse Request is the extension of the target resource file (this is ASPX ), and the corresponding Ispai is known as ASP.net ISAPI through ISAPI Extension Mapping . The then loads Aspnet_isapi.dll . So far, the processing of the request is handled by the ASP.net ISAPI, . The ASP.net ISAPI creates a worker Process (if the process does not exist) that is called aspnet_wp.exe and loads the CLR when aspnet_wp.exe initializes , thereby creating a managed runtime environment for ASP.net application , which loads two important DLLs in the CLR initialization (use): Appmanagerappdomainfactory and Isapiruntime . Create a application Domain for application by appmanagerappdomainfactory the create method, through Isapiruntime The processrequest handles request , which in turn drags the process into the category of ASP.net http Runtime Pipeline asp.net http Runtime Pipeline Handling HTTP Request is a relatively complex process, and the related introductions will be placed in the next part of this article. Here we can think of it as a black box that takes over the request and eventually generates HTML .

This is basically the entire process, very simple. However, there are a few points that need to be highlighted here.

1. First, the same host on the same time can only run a aspnet_wp process, each based on the virtual directory asp.net application corresponding to a application Domain, That is, each application is running in the same worker Process , and the isolation between application is based on application Domain rather than on Process of the.

2. Second, ASP.net ISAPI is responsible for creating the aspnet_wp Worker process andmonitoring the process, if the performance of aspnet_wp is detected Lower to a set lower limit, asp.net ISAPI is responsible for ending the process. After the aspnet_wp is finished, subsequent request will cause the asp.net ISAPI to recreate the new aspnet_wp Worker Process.

3. Finally, as IIS and application operate in their respective processes, communication between them must be based on specific communication mechanisms. Essentially , the communication between the Inetinfo process in which IIS resides and the worker process is communication between different processes on the same machine (local interprocess communications), In the performance, they adopted a communication mechanism based on named pipe . Communication between the ASP.net ISAPI and the worker Process is implemented through a set of pipe between them . Also in the performance, asp.net ISAPI passes the request to the worker Process and obtains the response in an asynchronous manner , but the worker Process is to get some server-based variables to the ASP.net ISAPI in a synchronized manner .

2. Second,IIS 6 based Process Model

Reliability and Performance will never be the subject of constant software development. These two aspects are particularly important as host based HTTP application IIS. From the evolution of IIS 5.x to IIS 6 , it is easy to see that the improvements that IIS 6 made on the basis of the previous version are also based on these two aspects. Before we introduce the processing model for IIS 6, let's take a look at the flaws in the IIS 5.x :

1. First of all, from the performance , IIS and application run in different processes, although they used asynchronous communication based on named Pipe , But the impact of a process-based communication on performance really cannot be fundamentally solved.

2. Second, from reliability, one machine can run only one worker process, each application running in the same process, although based on application Domain Isolation can provide a certain amount of reliability, but once the whole process collapses, all application are affected. So we sometimes need to provide a process based isolation.

The

is based on reliability improvements, and IIS 6 introduces application Pool . As the name suggests, the application pool is a application container, and in IIS 6 We can create a number of application pool to create a web When application , we specify an established application pool for it. At run time, a application corresponds to a worker Process : W3wp.exe . In other words, unlike the previous version of IIS , for IIS 6 , multiple worker process , each worker process , can be run concurrently on the same machine Each application domain corresponds to a application in. In this way, application not only provides application Domain -level isolation, you can also place different application in different application Pool , This is based on process level isolation. For host Some important application , such a way can provide a good reliability .

On the performance side, IIS 5.x listens for request through InetInfo.exe and distributes the request to the work Process. In other words, the listener and distribution of the request in IIS 5.x is done in user mode , which is ported to kernel mode in IIS 6 , All of this is done through a new component: HTTP.sys .

Note: to avoid user applications accessing or modifying critical operating system data, Windows provides two types of processor access modes: User modeand kernel mode (Kernel mode). Generally, the user program runs under user mode , while the operating system code runs under kernel mode . the code in Kernel Mode allows access to all system memory and all CPU instructions. For the user mode and kernel mode and some of the content at the bottom of windows, we recommend that you look at the Microsoft Windows InternalFour Edition, Authored by Mark E.russinovich & David A. Solomon.



The above diagram basically demonstrates theIIS 6The entire processing process. InUser ModeUnderHTTP.sysReceived a based on theaspxOfHTTP request, and then it will be based onIisIn theMetabaseView this based on theRequestOfApplicationbelong to whichApplication Pool if the application Pool does not exist, it is created. Otherwise, the request is sent directly to queue corresponding to application Pool . As I said above, each application Pool corresponds to a worker Process : W3wp.exe , which is undoubtedly running under User mode . The mapping of application Pool and worker process is maintained in IIS Metabase . Was (WEB Administrative Service ) according to such a mapping , will exist in one of application Pool Queue 's request Passed to the corresponding worker process ( if not, create such a process) . When the worker process is initialized, load Asp.net isapi , Asp.net isapi and then load the CLR . The final process is the same as the IIS 5.x : The Create method of Appmanagerappdomainfactory application creates a application Domain ; processrequest process request through Isapiruntime , which moves the process into asp.net Http Runtime Pipeline .

The

describes the IIS Process Model section here, and in the next section, I'll introduce asp.net Http Runtime Pipeline .

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.