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