ASP. NET Request Processing Process

Source: Internet
Author: User

HTTPProcessing Flowchart

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 all part of the entire asp.net cycle. All IhttpHandler operations are performed on the Application.PreRequestHandlerExecuteEvents andPostRequestHandlerExecuteThe Operations completed between events are page-level operations in IHttpHandler, 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, seeValidateRequestAndScript intrusion Overview.

2. If the file already exists in the Web. config fileUrlMappingsSectionIf any URL is configured in this section, perform URL ing.

3. CauseBeginRequestEvent.

4. CauseAuthenticateRequestEvent.

5. CausePostAuthenticateRequestEvent.

6. CauseAuthorizeRequestEvent.

7. CausePostAuthorizeRequestEvent.

8. CauseResolveRequestCacheEvent.

9. CausePostResolveRequestCacheEvent.

10. Based on the file extension of the requested resource (ing in the configuration file of the Application), select the implementationIHttpHandlerTo process the request. If the request isPageObject (PAGE) derived from the class, and the page needs to be compiled, ASP. NET will compile the page before creating the instance.

11. CausePostMapRequestHandlerEvent.

12. CauseAcquireRequestStateEvent. (Triggered when the initialization Session is loaded)

13. CausePostAcquireRequestStateEvent.

14. CausePreRequestHandlerExecuteEvent. (Triggered before an HTTP request is sent to HttpHandler)

15. Call the appropriateIHttpHandlerClassProcessRequestMethod (or asynchronous versionBeginProcessRequest). For example, if the request is for a page, the current page instance processes the request.

16. CausePostRequestHandlerExecuteEvent. (Triggered after an HTTP request is sent to HttpHandler)

17. Cause

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.