Simple Analysis of MVC Request Process (1): mvc Request Process Analysis

Source: Internet
Author: User

Simple Analysis of MVC Request Process (1): mvc Request Process Analysis

The server determines the type of the File Uploaded by the client. If the file is a static file, it returns directly and is displayed on the page output. If it is a dynamic file, it is transferred to the. NetFrameWork framework for execution through aspnet_isapi.dll.

Create an ISAPIruntime object and execute the ProcessRequest () method in the ISAPIruntime object.

The ProcessRequest () method can be seen as an entry point to access Asp. Net.

 

ProcessRequest () method:

Search for resources based on the passed handle (request message number), create the ISAPIWorkerRequest object wr, encapsulate the content of the request message into wr, and upload wr to HttpRuntime.

 

ProcessRequestNoDemand () method:

 

ProcessRequestNow () method:

 

ProcessRequestInternal () method:

Create an HttpContext object and encapsulate the request message wr in the context.

Create an HttpApplication object by using the GetApplicationInstance method of the factory class HttpApplicationFactory (). Create in the HttpApplication pool, that is, operate in the stack. The pool has the same lifetime as the application.

 

GetApplicationInstance ():

This is the method in GetApplicationInstance (), the factory class for creating the HttpApplication object.

There are three key methods to create an HttpApplication object.

The first method: EnsureInited ():

Double Lock this factory class, check whether HttpApplicationFactory is initialized, this represents the factory class HttpApplicationFactory. If not, use this. Init () to initialize the SDK. First, use this. GetApplicationFile () to find the address of the global. asax file and obtain the global. asax file. Call this. CompileApplication () method to compile the global. asax file to obtain the theApplicationType type.

Method 2: EnsureAppStartCalled (context ):

Obtain the global. asax file, call it, and make sure that the Application_Start () method in the global file is called only once when the program is started. Obtain all route information.

Method 3: GetNormalApplicationInstance (context ):

Create an HttpApplication object and call the InitInternal () method to initialize the object. Read all the configurations for the module in the configuration file. Obtain the module defined by the system and the module defined by the programmer, save it to the HttpModuleCollection collection, and traverse and read the HttpModuleCollection collection.

 

After creating an HttpApplication, enter the request pipeline.

 

 

When initializing HttpApplication, you can get the module defined by the system and the programmer.

View the system-defined module: UrlRoutingModule

Find the Init () method to initialize the module

 

UrlRoutingModule. Init () method:

The initialization module registers the OnApplicationPostResolveRequestCache event to the seventh event of the pipeline, and executes this method when it reaches the seventh event in the request pipeline.

 

OnApplicationPostResolveRequestCache () method:

The event triggered by the HttpApplication object. sender indicates the source of the event. All sender can be converted to HttpApplication.

The HttpContextBase class is an abstract class, which contains the same members as the HttpContext class. You can use the HttpContextBase class to create some Derived classes. These derived classes are similar to the HttpContext class, but can be customized and used outside the ASP. NET pipeline.

Use HttpContextBase to create the context object.

Further encapsulate the request content in the context object.

Execute the PostResolveRequestCache (context) method.

 

PostResolveRequestCache () method:

Match the HTTP request of the route, search for the route handler, and set the handler as the HTTP handler of the current request.

Match the obtained routing rules with the request packets in the encapsulated context to return route data.

Obtains the route request object, some methods in the message, and determines whether it is null.

If the route data is not null, the match is successful and the route data attributes are obtained.

Encapsulate the request message once, return an instance, and use the IHttpHandler object httpHandler to receive it.

The httpHandler here is MVCHandler. The MVCHandler class in the MVC source code inherits IHttpAsyncHandler, IHttpHandler, and IRequiresSessionState.

Finally, the current request is mapped to HttpHandler.

 

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.