Asp.net HTTP request processing process

Source: Internet
Author: User
When an HTTP request arrives at the server

When the server receives an HTTP request, IIS first needs to determine how to process the request (Note:Is it true that the server processes A. htm page and A. ASPX page ). So what does IIS do? -According to the file suffix.

The server obtains the requested page (Note:It can also be an extension of a file, such as jimmy.jpg). Then, the server will find an application that can process such extensions. If IIS cannot find an application that can process such files, this file is not protected by the server (Note:A protected example is the file in app_code, and an unprotected example is your JS script). Then IIS will directly return the file to the client.

Applications that can process various extensions, usually called ISAPI applications (Note:Internet server application programe interface, Internet server application interface ). Although this ISAPI sounds very elegant, it is also an "application", but you can see it by looking at its full name:It is actually only an interface that acts as a proxy. Its main task is to map the requested page (File) and the actual processing program corresponding to the suffix.

Let's take a closer look at the ISAPI and see what it looks like. Please follow the steps below:

  1. Open IIS.
  2. Select a site at will, right-click the site, and select "properties ".
  3. Select the "home directory" tab.
  4. Select "configuration ".

You should see the following picture:

Figure 1. Application configuration

Clearly, we can see that all the file types that can be processed by IIS or that is called the proxy service provided by ISAPI and their corresponding actual background processing programs are clearly listed here.

Find the. aspx application handler and click "edit". The following figure is displayed:

Figure 2. Edit the. aspx file Handler

All the way here, we can see that all. aspx files are actually processed by the aspnet_isapi.dll program. after the request for the ASPX page is submitted to aspnet_isapi.dll, it no longer cares about how the request is processed subsequently. Now we should know:ASP. NET is only an integral part of Server (IIS). It is an ISAPI extension.

Note the following two points:

  • After you change "limit to", you can restrict access to pages (Files) in a specific way.
  • "Check whether a file exists" is a key option for URL address ing. I will detail it later.
Understanding the host environment (hosting)

In essence, ASP. NET is mainly composed of a series of classes whose main purpose is to convert HTTP requests into responses to clients. The httpruntime class is a main entry of ASP. NET. It has a method called processrequest. This method uses an httpworkerrequest class as a parameter. The httpruntime class contains almost all information about a single HTTP request: the requested file, server variables, querystring, and HTTP header information. ASP. NET uses this information to load and run the correct file and convert the request to the output stream. Generally, it is an HTML page.

Note:In other words, it can also be an image.

When the content of the Web. config file changes or the. aspx file changes, in order to uninstall the application running in the same process (Note:To reload), HTTP requests are divided into isolated application domains.

Note:You may have heard of the application domain before, but you don't know what's going on. The application domain is appdomain.

For IIS, it depends on a built-in driver called HTTP. sys to listen to HTTP requests from outside. When the operating system is started, IIS first registers its own virtual path in HTTP. sys.

Note:Actually, it is equivalent to telling HTTP. sys which URLs are accessible and which are inaccessible. For example, why do you encounter a 404 error when accessing a non-existent file? It is determined in this step.

If the request is an accessible URL, HTTP. sys will send the request to the IIS worker process.

Note:Iis6.0 is called w3wp.exe, and iis5.0 is called aspnet_wp.exe.

Each worker process has an identity and a series of optional performance parameters.

Note:Optional performance parameters, such as the recycle mechanism settings and timeout settings.

The next step is the ISAPI described in the previous chapter.

In addition to the corresponding handler of the ing file, ISAPI also needs to do some other work:

  1. Obtain the current HTTP request information from HTTP. sys and save the information to the httpworkerrequest class.
  2. Load httpruntime in the appdomain of the mutually isolated application domain.
  3. Call the processrequest method of httpruntime.

The next step is the work that programmers usually write. Then, IIS receives the returned data stream and returns it to HTTP. sys, and finally, HTTP. sys then returns the data to the client browser.

Figure 3. ASP. NET host environment

Understanding Pipelines)

In the previous two chapters, we discussed at a relatively low level what IIS and framework did in a second from sending an HTTP request to seeing the browser output. However, we ignore the details of how the Code Compiled by the programmer is connected in this process. Let's take a look at this issue in this chapter.

When an HTTP request enters ASP. net runtime, its pipeline consists of a hosting module (Note: managed modules) and a processing program (Note: handlers), and the pipeline is used to process this HTTP request.

Figure 4. Understand the HTTP Pipeline

Let's take a look at how the data in this figure flows by number.

1. httpruntime transfers an HTTP request to httpapplication. httpapplication represents a web application created by a programmer. Httpapplication creates an httpcontext object for this HTTP request. These objects contain many other objects related to this request, including httprequest, httpresponse, and httpsessionstate. These objects can be accessed through the page class or context class in the program. ,

2. Next, the HTTP request uses a series of modules that have full control over the HTTP request.These modules can do things before performing a specific task..

3. After the HTTP request passes through all modules, it will be processed by httphandler. In this step, perform some actual operations, usually the business logic completed on the. ASPX page. You may not understand this process when creating the. ASPX page. However, you must know that the. ASPX page inherits from the page class. Let's take a look at the page class signature:

Public class page: templatecontrol, ihttphandler {
// Code omitted
}

As you can see, the page class implements the ihttphandler interface, and httphandler is also the lowest layer for HTTP request processing.

4. After httphandler completes processing, the HTTP request returns to the module again,At this time, the module can do some things after some work has been completed.

Note:Pay attention to the words marked in red, and think back: Is there many paired events such as inserting and inserted in ASP. NET? In fact, ASP. NET can divide an insert operation into two parts, and then intercept the background principles of the event separately.

If we focus only on HTTP requests, httphandler, and httpmodule without considering httpcontext and httpapplication, figure 4 can be simplified as follows:

Figure 5. http request flow direction in httphandler and httpmodule

// Reference: http://www.51jquery.com/2009-04/http-flow/

Http://www.cnblogs.com/txdlf/articles/462286.html
PDF: http://www.tracefact.net/Document/Http-Request-Processing-Flow.pdf

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.