博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Asp.Net Mvc 3.0

Posted on 2011-03-23 14:00  a-peng  阅读(336)  评论(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进行验证

Route Tester

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
controller test 
action Index 
id
Data Tokens
KeyValue


All Routes
Matches Current RequestUrlDefaultsConstraintsDataTokens
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

RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);