ASP. NET routing allows you to use URLs that do not need to be mapped to specific files on the website. Because the URL does not need to be mapped to a file, you canProgramUsing URLs. These URLs are descriptive user operations, so they are easier to understand.
In an ASP. NET application that does not use routing, URL input requests are usually mapped to physical files on the disk, such as. aspx files. In ASP. NET routing, you can define the URL mode, which contains placeholders of the values used when processing URL requests. During running, the URL section after the application name is analyzed as a discrete value based on the URL mode you have defined.
ASP. NET routes are different from other URL rewriting solutions. URL rewriting processes incoming requests by actually changing the URL before sending the request to the webpage. In addition, there is usually no corresponding API for URL rewriting to create a pattern-based URL. In URL rewriting, if the URL mode is changed, you must manually update all hyperlinks containing the original URL.
Because ASP. NET routes can extract values from URLs, the URL is not changed when processing incoming requests. If you must create a URL, pass the parameter value to the method that generates the URL for you. To change the URL mode, change the mode at a certain location. All links created in the application based on this mode will automatically use the new mode.
The defined URL mode is called "routing ". In routing, you can specify placeholders for ing to values analyzed from URL requests. You can also specify the constant value used to match the URL request.
In routing, you can use braces ({And}) to enclose placeholders to define placeholders ("URL parameters "). The/character is interpreted as a separator when the URL is analyzed. The information in the routing definition that is not a separator and is not in braces is considered as a constant value. Assign the extracted values between two delimiters to placeholders.
You can define multiple placeholders between separators, but they must be separated by a constant value.
ASP. NET route debugging
At the mix conference, Scott hanselman's demonstrated a simple route Test Program (route tester ), this tool displays the route data content (the route data in the page) in the request address in the current address bar ). Therefore, you can enter various URLs in the address bar to see which path it matches. At the bottom of the page, all the defined route lists in your program are displayed. It allows you to see which route the current URL matches. The utility of this tool is that sometimes the matching path you want is replaced by other path definitions. It can show you this situation.
To use this tool, you only need to download the ZIP file, put the DLL file in the bin directory of your program, and add a line in the appliation_start function of the global. asax. CS file.Code(In black ).
Protected void application_start (Object sender, eventargs E)
{
Registerroutes (routetable. routes );
Routedebug. routedebugger. rewriteroutesfortesting (routetable. routes );
}
It uses debugroutehandler to update all the route handlers (iroutehandler) in your application. These route handlers were originally defined for each different route in the processing program.
For details, see ASP. NET routing debugger.
Http://www.informit.com/content/images/9780672329982/samplepages/0672329980_CH02.pdf