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 );}