ASP. NET Request Processing Process

Source: Internet
Author: User
Document directory
  • Others
HTTP Processing Flowchart

 

Some concepts of the above process:

1. http. sys

It is a core component of the operating system in Win2003 and WinXP SP2. It enables any application to communicate with each other over http through its interfaces.

Tip: If you accidentally delete the driver file, you don't have to worry about it. The driver will be rebuilt the next time the system starts. Is a core component of the system that cannot be deleted! After the utility ends the driver, the driver will be re-created immediately (only the files to be crushed cannot be re-created immediately, but after the driver is crushed, it will be re-created next time ).

Microsoft introduced a new http api and kernel mode driver Http. sys in Windows 2003 Server to make Http service-based programs more efficient. The direct beneficiaries of this change are IIS 6.0 and ASP. NET.

In fact, after Windows XP installs SP2, Http. sys has already appeared in the system, but in fact, the operating system does not actually use this kernel-level driver, and IIS 5.1 on XP does not use HTTP APIs.

The core changes in the new http api are encapsulated in the kernel mode driver of Http. sys. Previously, HTTP-based programs run in User mode, and must handle software interruptions, context switches, thread scheduling, and other issues by themselves, and are often unable to freely access system resources. In the past, HTTP servers, such as IIS and Apache, used Winsock APIs to create a network listener in User mode. The Network listener (I. e.: per application or per thread basis) occupies an IP port. In layman's terms, only one application can listen to one port at a time, which is sometimes an uncomfortable restriction.

The new Http. sys offers the following benefits:

1. cache-static content is now cached in kernel mode, which makes the service response faster.

2. Log-IIS's log function is faster and standardized

3. bandwidth control-greater scalability control and throttling

4. reliability-all service requests are sent over Http. in sys, it is saved into the queue rather than processed by the service program itself. In this way, even if the service program is restarted, the unprocessed requests will not be lost.

5. IP port reuse-now, as long as it is through Http. the ports managed by sys (including the famous ports such as 80) can be monitored by multiple programs at the same time.

2. Application pool

Application pool is the application pool:
The application pool is introduced in Microsoft IIS6, a new concept of Microsoft: The application pool is a configuration that links one or more applications to one or more worker processes. Because applications in the application pool are separated from other applications by working process boundaries, applications in an application pool will not be affected by problems caused by applications in other application pools. Windows 2003 supports two working modes at the same time. The default is ISS 6.0 Working Process Isolation Mode. Working Process Isolation Mode prevents one application or site from being stopped and affects another application or site, greatly enhancing the reliability of IIS. So how to set two working modes?
Start IIS manager, right-click the website, and select "properties" to open the Properties dialog box. In IIS 6.0 Working Process Isolation Mode, all application code runs in the isolation environment. How are they isolated? In Windows 2003, an application pool is added. The working process isolation mode allows you to create multiple application pools. Each application pool can have different configurations. Because these application pools receive their requests directly from the kernel rather than the WWW Service, the performance and reliability are enhanced. To isolate Web applications running on the same computer but belonging to different websites, you need to create a separate application pool for each website.
Create application pool
In IIS manager, open the local computer, right-click application pool, and choose new application pool (the application pool can be created only in Working Process Isolation Mode ). In the application pool Name box, enter a new application pool name. If the ID (for example, AppPool #1) that appears in the "application pool ID" box is not what you want, you can rename it. If you click "use existing application pool as template", right-click the application pool you want to use as the template in the "application pool name" box. Click [OK].
Assign application pool
In IIS manager, right-click the application for which you want to assign an application pool, and then click Properties ". Click the "home directory" tab to confirm whether the "Application name" of the directory or virtual directory you are assigning has been filled in. If the "Application name" box is not yet filled, click "CREATE" and enter a name.
In the application pool list box, select the name of the application pool you want to assign to it. Click [OK].

 

3. aspnet_isapi.dll

This file is the processing file of asp.net. It is used to process files with extensions registered in iis, such as the default. register the aspx file with aspnet_isapi.dll so that the user can access it. the server automatically calls aspnet_isapi.dll to process the aspx file.

This DLL is a class library at the bottom of asp.net. This is its introduction:

When the client requests a * www process interception (www Service) from the web server and determines the file suffix, it forwards the request to ASPNET_ISAPI.DLL, and ASPNET_ISAPI.DLL uses an Http PipeLine, send the http request to the ASPNET_WP.EXE process. After the HTTP request enters the ASPNET_WP.EXE process, the asp.net framework processes the Http request through HttpRuntime and then returns the result to the client.

 

4. CLR

Http://developer.51cto.com/art/200910/158022.htm

Http://developer.51cto.com/art/200909/152551.htm

5. AppDomain

Http://www.cnblogs.com/chorrysky/archive/2008/07/16/1244089.html

6. ISAPIRuntime

Manage HttpWorkerRequest in. NET Framework (this abstract class defines the basic auxiliary methods and enumeration for processing requests managed by ASP. NET code) object.

 

Bytes -----------------------------------------------------------------------------------------------------------------------------

The action when the first request arrives is shown in: 

 

 

After all core application objects are initializedHttpApplicationClass instance to start the application. If the application has a Global. asax file, ASP. NET will create the Global. asax class (fromHttpApplicationClass, and use the derived class to represent the application.

 

Each http request has an HttpApplication object to manage the request process.

Creates an HttpContext object for each http request. This object is accessible throughout the Http processing process.

 

The HttpApplication object is responsible for assembling the entire"HTTP request processing Pipeline (HTTP Pipeline)", Which is equivalent to a processing assembly line that allows the HttpContext object to pass through this line.

When the HttpContext object passes through different parts of the pipeline, the HttpApplication object will successively trigger a series of events. The HTTP Module can respond to these events and "process and process" The HttpContext object in the event response code ".

The HTTP module can be seen as a worker in the "Production Pipeline.

The HTTP module object is created in the InitModules () method of the HttpApplication object. The init method is called when the HTTP module object is created () method to register the event of the HttpApplication object.

 

In the middle of the pipeline (after processing related events), The HttpContext object is received by the final Page object (that is why it can be stored in ASP. the reason for accessing the HttpContext object through the Context attribute defined by the Page class ).

Each accessed ASP. NET page is converted into a"Page class derived from the Page class".

The Page class implements the IHttpHandler interface, which defines a ProcessRequest () method.

After the ASP. NET page class is generated, it is automatically compiled as an assembly, and its ProcessRequest () method is automatically called. The execution result of the ProcessRequest () method is carried by the HttpContext object again, and the control is switched back to the "HTTP request processing pipeline". The HttpApplication object continues to trigger subsequent events. At this time, if a specific HTTP module responds to these events, they will be automatically called.

 

The HttpContext object comes to the "HTTP request processing pipeline" with the final processing result. The information is retrieved and sent to the worker process using aspnet_isapi.dll as the bridge. The worker process then transfers the HTTP request processing result to HTTP. SYS, which is responsible for returning the result to the browser.

The page code we wrote and the complex page lifecycle are part of the entire asp.net cycle, all IhttpHandler operations, both the PreRequestHandlerExecute event of the Application and the PostRequestHandlerExecute event are completed. The operations in IHttpHandler are page-level operations, and they cannot cross-page operations.

IHttpModule should be used for application-level operations.

 

HttpApplication and HttpApplicationState must be separated.

HttpApplicationState is unique throughout the application.
HttpApplication is not unique.

The Application ["key"] = "" value you wrote on the page; this Application is actually HttpApplicationState

 

Each request is processed by an HttpApplication object. During the process, this object cannot process other requests. During Concurrent access, different HttpApplication objects are allocated for different accesses.

The HttpApplicationFactory object is used to manage an HttpApplication Object pool. When an HTTP request arrives, if there are still available HttpApplication objects in the pool, it is allocated. Otherwise, a new HttpApplication object is created. After the request is completed, HttpApplication will be recycled for reuse.

 

Each time a new HttpApplication object is created, a new Ihttpmodule object is created based on the configuration. When a new IHttpModule object is created, its init method is executed.

 

HttpApplicationList of events triggered at Different Processing Stages

1. Verify the request, check the information sent by the browser, and determine whether it contains potentially malicious tags. For more information, see ValidateRequest and script intrusion overview.

2. If you have configured any URL in the UrlMappingsSection of the Web. config file, perform URL ing.

3. The BeginRequest event is triggered.

4. The AuthenticateRequest event is thrown.

5. Trigger the PostAuthenticateRequest event.

6. Cause the AuthorizeRequest event.

7. Trigger the PostAuthorizeRequest event.

8. Trigger the ResolveRequestCache event.

9. The PostResolveRequestCache event is triggered.

10. Based on the file extension of the requested resource (ing in the application configuration file), select the class that implements IHttpHandler to process the request. If the request is for an object (Page) derived from the Page class and needs to compile the Page, ASP. NET will compile the Page before creating an instance.

11. Trigger the PostMapRequestHandler event.

12. The AcquireRequestState event is triggered. (Triggered when the initialization Session is loaded)

13. Trigger the PostAcquireRequestState event.

14. Trigger the PreRequestHandlerExecute event. (Triggered before an HTTP request is sent to HttpHandler)

15. Call the appropriateIHttpHandlerClass ProcessRequest method (or asynchronous BeginProcessRequest ). For example, if the request is for a page, the current page instance processes the request.

16. The PostRequestHandlerExecute event is thrown. (Triggered after an HTTP request is sent to HttpHandler)

17. Trigger the ReleaseRequestState event. (Triggered when Session status is stored)

18. The PostReleaseRequestState event is triggered.

19. If the Filter attribute is defined, the response is filtered.

20. The UpdateRequestCache event is triggered. (Triggered when cache information is updated)

21. Trigger the PostUpdateRequestCache event.

22. An EndRequest event is triggered.

Others

Use naming conventionsApplication_ Event(For exampleApplication_BeginRequestASP. NET can automatically bind application events to the handler in the Global. asax file. This is used to automatically bind the ASP. NET page method to an event (such asPage_LoadEvent.

If the file extension has not been mapped to ASP. NET, ASP. NET will not receive the request. This is important for applications that use ASP. NET authentication. For example, because. htm files are not normally mapped to ASP. NET, ASP. NET does not perform authentication or authorization checks on. htm file requests. Therefore, even if the file only contains static content, If you want ASP. NET to check the authentication, you should also use the file extension mapped to ASP. NET to create the file, such as using the file extension. aspx.

To create a custom handler for a specific file extension, you must map the extension to ASP in IIS.. register the handler in the config file. For more information, see HTTP handler introduction.

Sessions are available during the period from the AcquireRequestState event (including this event) to the PostRequestHandlerExecute event (excluding this event. The Httphandler ProcessRequest method is also called during this period. Therefore, you can use Session ["key"] to access the Session on the page.

 

Other references: http://www.cnblogs.com/stg609/articles/1224943.html

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.