Series directory
ASP. net mvc request service process
It represents the service process of a common ASP. net mvc request:
We can see how an httprequest is executed by the ASP. NET and ASP. net mvc frameworks. After processing by IIS and ASP. NET, Core routing first matches the URLFiles on the physical pathThe Core routing moduleRoute execution, After the route is matched,MvcroutehandlerThe request will be "brought" into the MVC framework, and the Controller and action will be executed. The action can be directly injected into the response, or, more often,Actionresult,ActionresultOfExecutedresultThe method will be called.Viewresult(Inherited from actionresult), it will use webformviewengine to convert an HTML and inject it into response.
The above process will be analyzed and understood in detail in future series.
What is the URL mechanism?
URL ingIt is not a mechanism of MVC, but MVC fully depends on it and gives full play to its advantages. It is located at the front end of the MVC Framework and is the entry point of the MVC main framework. Traditional URLs often correspond to files in the physical path of the server disk. The mvc url mechanism breaks this constraint, so that the file organizations on the server can no longer be exposed to the public, it maps to the Controller and action. The URL mechanism involves two main tasks:
1.Forward URL ing (Inbound) To controller and action
2.Controller and action reverse ing (Outbound) And construct the URL
Set route
Let's review the basic content. ApplicationProgramAt the initial startup, You need to register a URL like the following:
Routes. maproute (null, "{controller}/{action}", new {controller = "carview", Action = "Index "});
the maproute of the Code is actually an extension of routecollection ., it has multiple reloads. Let's take a look at the source code of the maproute most complex overloaded version:
Public static route maproute (this routecollection routes, string name, string URL, object ults, object constraints, string [] namespaces) {If (routes = NULL) {Throw new argumentnullexception ("Routes");} If (u RL = NULL) {Throw new argumentnullexception ("url");} route = new route (URL, new mvcroutehandler () {defaults = new routevaluedictionary (defaults ), constraints = new routevaluedictionary (constraints)}; If (namespaces! = NULL) & (namespaces. length> 0) {route. datatokens = new routevaluedictionary (); route. datatokens ["namespaces"] = namespaces;} routes. add (name, route); Return Route ;}
from the source code, maproute constructs a route object and adds it to the global routecollection: routetable. routes . Routecollection is a set of routebase. The route object inherits from routebase . First, let's take a look at some attributes of the route Object:
| Attribute name |
Description |
| URL (string) |
URL model to be matched, where {} is used to define the parameter name |
| Routehandler (iroutehandler) |
When the route matches, iroutehandler should process the request |
| Defaults (routevaluedictionary) |
Provide a default table for parameters |
| Constraints (routevaluedictionary) |
Provide a matching rule table for parameters |
| Datatokens (routevaluedictionary) |
Provides a basis for selecting the Controller for Route handler. It is mainly used for the areas mechanism. |
These attributes will be discussed in depth below.
Labor fruit, reproduced please declare Source: http://www.cnblogs.com/P_Chou/archive/2010/11/01/details-asp-net-mvc-01.html