MVC Study Notes 3 understanding Routing

Source: Internet
Author: User

ASP. net mvc uses URL for driver.

• System. Web. Routing. dll
• Components independent of ASP. net mvc Framework,Can be used for any ASP. NET applicationProgram
• ASP. net mvc framework openSource code
• The URL routing component is not currently available
• Convert a URL to routedata and other data

Urlrouting is used to make the URL shorter and more meaningful. For example: default. aspx? The URL of year = 1999 & month = 3 & day = 8 is/default/1999/3/8 /.

Similar to home/about. aspx? Id = 1. The {controller}/{action}/{ID} rule defined in global. asax. CS in the example is used as the column.
/Home/about/1 is actually a querystring parameter for accessing controller = "home" Action = "about": Id = "1"

 

You can use urlrouting to configure URL ing so that users can access the website according to your rules.
When using urlrouting, you must specify the URL mode. It includes a location ID that will be returned to you according to this rule when you request a webpage. of course, the created rule is completely defined by you.
The last response shows how to access index. aspx and about. aspx:

However, http: // localhost/views/home/index. aspx and http: // localhost/views/home/about. aspx cannot directly access the following two files:
Views/home/index. aspx and views/home/about. aspx

What is the problem? How can we access it?
The answer is:
Http: // localhost/home and http: // localhost/home/about
Why?

This is the urlrouting function, and the configuration of this function is defined by the URL request rule, which is defined in global. asax. CS.

         Public   Static   Void Registerroutes (routecollection routes ){ // Is not controlled by subsequent rules. Ignore is ignored. Routes. ignoreroute ( "{Resource}. axd/{* pathinfo }" ); // Rewrite the rule Routes. maproute ( "Default" , // Route name                  "{Controller}/{action}/{ID }" ,// URL with Parameters                  New {Controller = "Home" , Action = "Index" , Id = "" } // Parameter defaults );} Protected   Void Application_start () {registerroutes (routetable. routes );}

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.