Asp.net programming model record 1

Source: Internet
Author: User

Http request processing process

 

When an Http request arrives at the server

 

When the WEB server receives an Http request, IIS first needs to determine how to process the request (NOTE: the webserver must process a .htm page and A. aspx page ). So what does IIS do? -According to the file suffix.

After the WEB server obtains the suffix of the requested page (NOTE: it can also be a file, such as jimmy.jpg), it will find an application on the WEB server that can process such extensions, if IIS cannot find an application that can process such files, and the file is not protected by the server (NOTE: A protected example is the file in App_Code, an unprotected example is your js script), so IIS will directly return this file to the client.

 

Applications that can process various extensions are generally 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 random site, right-click the site, and select "properties ".

3. Select the "home directory" tab.

4. Select "configuration ".

<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. The main purpose of these classes 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 general, it can also be an image.

 

When the Web. the content of the config file is changed or. when the aspx file changes, in order to be able to uninstall applications running in the same process (NOTE: unmount is also to re-load), 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 Setting and timeout setting.

 

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 Httq request information from HTTP. SYS and save the information to the HttpWorkerRequest class.

2. Load HttpRuntime in the AppDomain of the 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 be used before a specific task is executed.

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

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 it has completed.

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

This article focuses on three parts:

1. What does IIS do when the Http request arrives at IIS.

2. Http request host environment

3. Http pipeline.

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.