Asp.Net Mvc 3.0

1. Url routing

    routes.MapRoute(

"Default", // Route name

"{controller}/{action}/{id}", // URL with parameters

new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults

);

    http://site.com/ > controller = Home, action = Index

    http://site.com/home/index > controller = Home, action = Index

    http://site.com/home/index/1 > controller = Home, action = Index, id = 1

http://site.com/test > controller = test, action = Index

    使用http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx进行验证

Type in a url in the address bar to see which defined routes match it. A {*catchall} route is added to the list of routes automatically in case none of your routes match.

To generate URLs using routing, supply route values via the query string. example: http://localhost:14230/?id=123

: {controller}/{action}/{id}

Route Data
KeyValue
controllertest
actionIndex
id
Data Tokens
KeyValue

All Routes
Matches Current RequestUrlDefaultsConstraintsDataTokens
FalseAdmin/{controller}/{action}/{id}action = Index, id =(null)Namespaces = System.String[], area = Admin, UseNamespaceFallback = False
False{resource}.axd/{*pathInfo}(null)(null)(null)
True{controller}/{action}/{id}controller = Home, action = Index, id =(null)(null)
True{*catchall}(null)(null)(null)

Current Request Info

AppRelativeCurrentExecutionFilePath is the portion of the request that Routing acts on.

AppRelativeCurrentExecutionFilePath: ~/test

RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);