The second analysis of WCF technology: talking about IIS and asp.net pipeline

Source: Internet
Author: User
Tags http request iis metabase

IIS 5.x and ASP.net

Let's take a look at how the IIS 5.x handles requests based on asp.net resources (such as. Aspx,.asmx, etc.), and the whole process can be illustrated in Figure 1.

IIS 5.x runs in process InetInfo.exe, and one of the most important services in the process is the Windows service called the World Wide Web Publishing Service (w3svc). The main features of W3SVC include monitoring of HTTP requests, management of worker processes, and configuration management (by loading related configuration information from metabase).

When an HTTP request is detected, the request is judged by the extension as a static resource (such as. Html,.img,.txt,.xml, etc.), and if so, the contents of the file are returned directly as HTTP response. If it is a dynamic resource (such as. aspx,asp,php, and so on), the appropriate ISAPI Dll is found from the script Map of IIS in the extension name.

Figure 1 IIS 5.x and asp.net

ISAPI is an acronym for the Internet server API (Internet Servers application programming Interface) and is a local (Native) Win32 API with high execution performance, is the link between IIS and other dynamic Web applications or platforms. For example, ASP ISAPI bridges IIS with ASP, while ASP.net ISAPI connects IIS with ASP.net. Ispai defined in a DLL, asp.net ISAPI corresponds to the DLL for Aspnet_isapi.dll, you can in the directory "%windir%\microsoft.net\framework\{version no}\" The DLL is found in the.

ISAPI supports ISAPI extensions (ISAPI Extension) and ISAPI Filters (ISAPI filter), the interface that really handles HTTP requests, which can view, modify, forward, or reject requests before HTTP requests are actually processed. For example, IIS can use ISAPI filtering to authenticate requests (authentication).

If we are asking for a resource type based on asp.net, such as:. aspx Web Page,. asmx Web service, or. svc WCF service, Aspnet_isapi.dll will be loaded, asp.net The ISAPI extension creates a ASP.NET worker process (if the process has not yet started), and for IIS 5.x, the worker process is aspnet.exe. The IIS process communicates with the worker process through a named pipe (Named pipes) process for best performance.

During worker process initialization, the. NET Runtime (CLR) is loaded to build a managed environment. For the first request for a Web application, the CLR creates a appdomain for it. In this AppDomain, the HTTP runtime (HTTP Runtime) is loaded and used to create the appropriate application. All Web applications that are hosted on IIS 5.x run in different AppDomain of the same process (worker process aspnet_wp.exe).

IIS 6 and ASP.net

With the above description, we can see that there are at least two deficiencies in the IIS 5.x:

The ISAPI DLL is loaded into the InetInfo.exe process, which is a typical way of cross process communication between the worker processes and, while adopting the best named pipes for performance, still poses a performance bottleneck;

All ASP.net applications run in the same process (aspnet_ Wp.exe) in different application domains (AppDomain), the isolation level based on the application domain does not fundamentally address the impact of one application on another, and in many cases we need different Web applications running in different processes.

In IIS 6.0, to solve the first problem, ISAPI.dll is loaded directly into the worker process. To solve the 2nd problem, the mechanism of the application pool (application pool) is introduced. We can create application pools for one or more Web applications, each of which corresponds to a separate worker process, providing a process-based isolation level for Web applications running in different application pools. The worker process name for IIS 6.0 is w3wp.exe.

Of course, in addition to the two improvements above, IIS 6.0 has other commendable points, the most important of which is the creation of a new HTTP listener: HTTP protocol stack (HTTP Protocol stack,http). SYS). HTTP. SYS runs under Windows kernel mode (Kernel mode) and exists as a driver. It is part of the TCP/IP network subsystem of Windows 2003, which, structurally, belongs to a network driver on top of TCP. Strictly speaking, HTTP. SYS is no longer part of IIS, so the HTTP.sys configuration information is not stored in the IIS Metabase (Metabase), but is defined in the registry. HTTP. The registry key for Sys is located in the following path: Hkey_local_machine/system/currentcontrolset/services/http. HTTP. SYS can bring the following benefits:

Continuous monitoring: Because HTTP.sys is a network driver, always in the running state, for the user's HTTP request, to be able to respond in a timely manner;

Better stability: HTTP.sys runs in OS kernel mode and does not execute any user code, so it is not itself affected by Web applications, worker processes, and IIS processes;

Kernel-mode data caching: If a resource is frequently requested, HTTP. SYS caches the contents of the response, and the cached content responds directly to subsequent requests. Since this is based on kernel-mode caching, there is no kernel-mode and user-mode switching, and the response speed will be greatly improved.

Figure 2 shows the structure of IIS and the process of processing HTTP requests. As you can see, unlike IIS 5.x, W3SVC is detached from the InetInfo.exe process (for IIS6.0, InetInfo.exe can basically be seen as a simple IIS management process) and runs in another process SvcHost.exe. However, the basic functions of W3SVC have not changed, but the function of the implementation of the corresponding improvements. As with IIS 5.x, the metabase (Metabase) still exists in the InetInfo.exe process.

Figure 2 IIS 6 and ASP.net

When HTTP.sys listens to the user's HTTP request, it is distributed to W3SVC. w3svc resolves the requested URL and obtains the target application based on the mapping relationship between the URL obtained from metabase and the Web application, and further obtains the application pool or worker process that the target application runs. If the worker process does not exist (not yet created or reclaimed), a new worker process is created for the request, which is known as a request-creation process. During the initialization of the work process, the corresponding ISAPI.dll is loaded, and for the ASP.net application, the loaded ISAPI.dll is Aspnet_ispai.dll. The ASP.net ISAPI is responsible for CLR loading, AppDomain creation, WEB application initialization, and so on.

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.