Asp. NET request processing mechanism initial exploration tour-Part 2 core

Source: Internet
Author: User
Tags httpcontext

In the previous article we learned about a request from the client to the server to receive and go to the ASP. NET processing portal, this article we began to explore the core processing of ASP, with powerful anti-compilation tools, we will see a few familiar and unfamiliar noun (class): HttpWorkerRequest ,HttpRuntime,HttpContext, HttpApplication and so on.

first entrance: isapiruntme.processrequest ()

Isapiruntime  is the entry into the net managed environment, in its PR method, through an ECB handle pointing to the memory address of the current request style, the HTTP request message is simply encapsulated as a

The isapiworkerrequest Object (this class inherits from the HttpWorkerRequest object) is then a variety of PR (ProcessRequest) methods that we often hear.

The request that is prepared for processing in ASP. NET must be encapsulated as an object of type HttpWorkerRequest, and HttpWorkerRequest is an abstract type.

second entrance: httpruntime.processrequest ()

when a request enters httpruntime, it decides how to handle the request. By default, the HttpRuntime node is not explicitly defined in Machine.config and Web. config, but the node has a default value. in general, we can change the default value of the HttpRuntime node in Web. config.

This PR method mainly will be the previous step The HttpWorkerRequest object is encapsulated as a HttpContext object . This is an important HTTP context object, and the fields of two important types are initialized with it:HttpRequest objects and httpresponse objects . We get to this instance through HttpContext.Current and the instance will survive the entire life cycle, and through it we can get some common objects, such as request,response,session and so on.

The next step is to get an object of type IHttpHandler from the HttpContext object, which is essentially a HttpApplication type , andHttpApplication is actually an instance of the Web application.

It is a good idea to go into the application pool instead of immediately destroying the connection pool after it finishes processing the request. By reflection, it can be seen that a HttpApplication instance is encapsulated in a class that is compiled by the Global file.

now HttpApplication needs to initialize the request processing pipeline to handle the response operations of pages of type ASP. NET WebForm or ASP. It performs its corresponding Init method on each of its httpmodule by reading the information about HttpModule in the Web. config configuration file and passing it to the collection of HttpModule. Next , complete the registration of the HttpApplication 19 pipeline events . All you need now is to invoke the execution method corresponding to each event in HttpModule.

About the request processing pipeline:

HttpApplication uses a process pipeline method to process, the process is divided into several steps, each step through the form of events exposed to the programmer, these events in a fixed order of processing sequence, the programmer by writing event processing method can customize each request of the extended processing process.

For HttpApplication, to the ASP. 4.0 version, 19 standard events are provided, as shown in:

As for the details in the request processing pipeline, we look at part 3 again, so far today, thank you!

Asp. NET request processing mechanism initial exploration tour-Part 2 core

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.