Asp. The nature of Net: IIS and Process mode __.net

Source: Internet
Author: User
Tags web services
ASP.net is a good framework for writing Web applications and components, but because of his sheer size, it seems impossible for many people to understand every detail of him, and I have always thought it necessary to understand how the basic structure works to get higher performance in design, and in the next series of articles I'm going to describe a The life cycle of the web, from when the request is accepted by the server, to the ASP.net pipeline processing until the generation of loopback information (such as: HTML) is later in the pipeline processing.

Introduced

Microsoft Active Server pages (Microsoft Dynamic Web Services), also known as ASP, was first released in the late 1996, providing programmers with a rich and complex framework for building Web applications. A few years later, his basic structure has improved a lot, What you now know about ASP.net.ASP.net is a framework for building Web applications, which means that he must be running on a Web service, using a customer-service-server-side model. Typically, browsers send different types of resource requests to a Web server. In the presence of dynamic server resource generation technologies (such as cgi,php,jsp and ASP), all Web services can only accept static resource requests from customer service and send them back to the customer service side.

Seemingly, this interaction between the server and the client is very simple. The session is conducted through the HTTP protocol, an application-level protocol built on TCP and IP protocols (used to exchange data between 2 connected to different types of network endpoints, as we know the WWW World Wide Web).

Essentially any dynamic server technology needs to run on a particular Web service, as well as asp.net closely with Microsoft Internet Information Services, also known as IIS.

Different services choose different ways to generate dynamic resources and so on ... We're going to parse how IIS does it when a request message arrives at the server and finally sends it back to the client.

IIS and ISAPI Extensions

As mentioned above, the static resource does not need to be processed by the server; Once such a resource request arrives at the server, the server only needs to find his content from the file system and send it to the client via the HTTP protocol as a stream of bytes. Static resources can be pictures, javascript,css, or plain HTML pages. Obviously the server needs to know how to differentiate between static and dynamic resources, and how dynamic resources need to be processed rather than sent back to the client directly. As a result, an ISAPI extension has occurred, and the ISAPI is an interface for programming Internet service applications. ISAPI is executed as a module as the early Win32.dll.IIS relies on ISAPI to process specific resources. By using IIS to map ISAPI extensions and files, each file extension type is associated with a specific ISAPI extension, that is, when a request for a file arrives, IIS processes and turns to the appropriate ISAPI extension to confirm that the request can be processed.

ISAPI extensions clearly need to conform to a common interface so they can be invoked by IIS and provide the necessary data to handle requests and generate loopback.

. The ASP extension is mapped to the Asp.dll ISAPI extension, and during the ASP processing period, the component is responsible for performing all the required tasks to generate the loopback, that is, by gathering the request information and enabling him to be available on the ASP page, other ASP internal objects, Parse and execute the ASP page and finally return the results in HTML.

Although this has been a great improvement relative to CGI technology, asp.net is more powerful.

After installing ASP.net, asp.net configures IIS to redirect the file requests specified by ASP.net to a new ISAPI extension aspnet_isapi.dll. This extension is somewhat different from the previous Asp.dll extension.

Table I:aspnet_isapi.dll Mappings in IIS Applications

Extension Resource Type
. asax asp.net application files. Commonly used are global.asax.
. ascx asp.net user control files.
. ashx HTTP handlers, the managed counterpart of ISAPI extensions.
. asmx asp.net Web services.
. aspx asp.net Web pages.
. axd asp.net internal HTTP handlers.

In addition to the file extensions listed in table 1, the asp.net ISAPI extension manages other file extension types that are typically not provided to browser access, such as Visual Studio engineering files, resource files, and configuration files.

Asp. NET processing model

So far, we have learned that when a request for a asp.net file is uploaded to IIS, he is forwarded to Aspnet_isapi.dll, the main entry point for asp.net related processing. In fact, this extension is obviously dependent on the version of IIS on the system, so the processing model is handled by the ASP.net runtime through an orderly operation to process the request and generate a loopback, perhaps with a little change.

In iis5.x, all asp.net related requests are assigned to an external worker process through an ISAPI extension called the Aspnet_wp.exe.ISAPI extension and run in the IIS process (Inetinfo.exe). Re-transfer control together with all information about the current incoming request to aspnet_wp.exe. 2 of interprocess communication is established by means of a named pipe (known as ipc[internal process communication) mechanism. Asp. NET worker process performs most of the tasks of the ISAPI extension. Note the nature of each Web application and the communication with different virtual directories under IIS, which are executed in the context of the same process as the ASP.net worker process. In order to implement the context asp.net in the execution of the reading, the application domain concept is introduced, abbreviated AppDomains. They can be considered a lightweight process. More will be introduced in the following.

If running on IIS6, the Aspnet_wp.exe process is not being used, choosing a better process is called w3wp.exe. At the same time, Inetinfo.exe is no longer used to pass HTTP requests to the ISAPI extension, although he remains in service for requests from other protocols. Although IIS6 can run in compatibility mode and simulate previous behavior, there have been a lot of changes relative to the previous IIS5 processing model. Relatively early maximum change, when the processing model runs on the IIS5, incoming requests are lower-kernel-level and then passed to the correct ISAPI extension, thus avoiding excessive operations in internal processing. In the following paragraphs, we will conduct a more in-depth study.

IIS5.0 Processing Model

This is the default processing model on Windows2000 and XP systems. As mentioned above, he has the IIS Inetinfo.exe process listens to TCP port 80 for incoming HTTP requests and pushes them into the queue for processing. If the request type is asp.net, processing is delegated to the asp.net ISAPI extension aspnet_isapi.dll. This takes turns communicating with the ASP.net worker process through a named pipe, which processes and delivers requests to the ASP.net HTTP runtime environment.

Elements we have not mentioned-asp.net the HTTP runtime environment. He is not the subject of our article at the moment, and he will be parsed in the following article. HTTP runtime can be treated as a black box, all asp.net specify that processing occurs here, all the controlled code runs the site, from the HTTP runtime to the HttpHandler final processing request and the generation of loopback are processed here. This also involves ASP.net pipelines or HTTP runtime pipelines.

One interesting thing about this model is that all requests, once processed by an ISAPI extension, are passed to the ASP.net worker process. Each activity time has and only one instance, one exception, discussed later. Therefore, the ASP.net Web application that is running on IIS is actually running on the worker process. However, this does not mean that all applications run on the same context and share all of their data. It is worth mentioning that the introduction of the AppDomain concept by asp.net is essentially a controlled lightweight process that provides independent and secure boundaries. Each IIS virtual directory executes in a AppDomain, and he is automatically loaded into the worker process as long as the resource is the application that belongs to the first request. Once the AppDomain is loaded, in other words, the current request for all required assemblies to be loaded into the appdomain– is actually passed to ASP.net pipeline processing. Several AppDomains can run this way in the same process, when multiple requests are available for the same AppDomain on multiple threads. However, a thread does not belong to a AppDomain, he can handle multiple requests for several different appdomians, but one thread at a given time belongs to a AppDomain.

For performance purposes, worker threads can be reclaimed based on some criteria (configured by machince.config files). These standards include process lifecycle, request and queue count, idle time, memory allocation. Once a critical value in these parameters is reached, the ISAPI extension generates a new worker process instance to process the request. In fact, the previous instance of the process was not shut down, but he was terminated by the service waiting for the request.

IIS6.0 Processing Model

IIS6 is the WINDOWS2003 system default. He has several changes and improvements on the IIS5 processing model. One of the biggest changes is the application pool concept. On the IIS5 series application, that is, all appdomains-run on the asp.net worker process. To achieve an excellent definition of security and features, the IIS6 processing model allows applications to run on different copies of the same worker process. Each application pool can contain multiple AppDomains (running on a separate worker process copy). In other words, this change is from running all programs from a single process to running every application pool in multiple processes. This model is also called the work process isolation mode.

Exception a large change relative to the previous model in IIS listening for all incoming data. In IIS5, the IIS process, inetinfo.exe listens on the specified TCP port. In IIS6, the incoming request is processed and the queue is replaced at the core level to replace the user mode previously invoked http.sys through the core driver; This method has several advantages that are called Kernel-level request queues relative to the previous pattern.


Once a request arrives at the core-level device-driven HTTP.sys, and then sent to the appropriate application pool queue, each queue belongs to a specified application pool.

The worker process is responsible for loading the asp.net ISAPI extension, sequentially loading the CRL delegation to all work to the HTTP runtime.

Unlike the aspnet_wp.exe below IIS5, the W3WP.exe process is not asp.net-specific and can be used to handle any type of request. What ISAPI modules are loaded according to the type of service resource required.
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.