Request the execution process of the Asp.net MVC application

Source: Internet
Author: User
Understanding the MVC application execution process (C #)

Requests to an ASP. net mvc-based Web application first pass throughUrlroutingmoduleObject, which is an HTTP module. This module parses the request and performs route selection.UrlroutingmoduleObject selects the first route object that matches the current request. (A route object is a class that implementsRoutebase, And is typically an instance ofRouteClass.) If no routes match,UrlroutingmoduleObject does nothing and lets the request fall back to the regular ASP. NET or IIS request processing.

From the selectedRouteObject,UrlroutingmoduleObject obtainsIroutehandlerObject that is associated withRouteObject. Typically, in an MVC application, this will be an instanceMvcroutehandler.IroutehandlerInstance createsIhttphandlerObject and passes itIhttpcontextObject. By default,IhttphandlerInstance for MVC isMvchandlerObject.MvchandlerObject then selects the Controller that will ultimately handle the request.

Note:
When an ASP. net MVC web application runs in IIS 7.0, no file name extension is required for MVC projects. however, in IIS 6.0, the handler requires that you map. MVC file name extension to the ASP. net isapi dll.

The module and handler are the entry points to the ASP. net mvc framework. They perform the following actions:

    • Select the appropriate controller in an MVC web application.
    • Obtain a specific controller instance.
    • Call the Controller'sExecuteMethod.

The following table lists the stages of execution for an MVC web project.

Stage Details
Receive first request for the application In the global. asax file,RouteObjects are added toRoutetableObject.
Perform Routing TheUrlroutingmoduleModule uses the First MatchingRouteObject inRoutetableCollection to createRoutedataObject, which it then uses to createRequestcontext(Ihttpcontext) Object.
Create MVC request handler TheMvcroutehandlerObject creates an instance ofMvchandlerClass and passes itRequestcontextInstance.
Create Controller TheMvchandlerObject usesRequestcontextInstance to identifyIcontrollerfactoryObject (typically an instance ofDefaultcontrollerfactoryClass) to create the Controller instance.
Execute Controller TheMvchandlerInstance callthe controller'sExecuteMethod.
Invoke action Most controllers inherit fromControllerBase class. For controllers that do so,ControlleractioninvokerObject that is associated with the Controller determines which action method of the controller class to call, and then CILS that method.
Execute result A typical action method might receive user input, prepare the appropriate response data, and then execute the result by returning a result type. The built-in result types that can be executed include the following:Viewresult(Which renders a view and is the most-often used result type ),Redirecttorouteresult,Redirectresult,Contentresult,Jsonresult, AndEmptyresult.

Original article: http://www.asp.net/learn/mvc/tutorial-22-cs.aspx

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.