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进行验证
Route Tester
: {controller}/{action}/{id}
Key | Value |
---|---|
controller | test |
action | Index |
id |
Key | Value |
---|
Matches Current Request | Url | Defaults | Constraints | DataTokens |
---|---|---|---|---|
False | Admin/{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