Routing and ASP. NET MVC life cycle

Source: Internet
Author: User

First, Routing  

The correspondence between the "URL path" and "Document path" for ASP. NET MVC is defined by "URL routing (Routing)", and we can see a registerroutes method from the App_start\routeconfig.cs document within the project:

public static void RegisterRoutes (RouteCollection routes)

{

Route. Ignoreroute ("{resource}.axd/{*pathinfo}");

Route. MapRoute (

Name: "Default",

URL: "{controller}/{action}/{id}",

Defaults:new{controller= "Home", action= "Index", id=urlparameter.optional}

);

}

In the RegisterRoutes method:

Ignoreroute the URL path for setting. Axd format does not run through ASP.

The Maproute method is the most important way to define ASP. URL Routing: name--route name, url--setting URL path to controller, action and route value, defaults--setting {controller}, {action}, {ID} The default values for these 3 route parameters.

Ii. ASP. NET MVC life cycle

The three main processes of the ASP. NET MVC life cycle are:

1. URL routing alignment;

By default, if the requested URL corresponds to an entity document relative to the root of the Web site, it will not be processed through ASP. NET MVC, but will be automatically skipped over all URL routing pairs and delivered directly to IIS or ASP. If you want to change this behavior, you can global.asax in the Application_Start () The RouteTable.Routes.RouteExistingFiles is set to true at the front of the event so that the UrlRoutingModule module does not first determine if there is an entity document, but rather a comparison of the URL routing rules defined by the registerroutes, if Will enter the MVC runtime, and will fail to return the run right to IIS.

2. Run the Controller and action;

3. Run the view and return the results.

Routing and ASP. NET MVC life cycle

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.