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


All Routes
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

RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);

相关文章:

  • 2022-01-23
  • 2021-10-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-01
  • 2021-10-06
  • 2021-09-19
猜你喜欢
  • 2021-05-28
  • 2021-05-18
  • 2021-12-05
  • 2022-01-17
  • 2021-12-20
  • 2022-02-11
相关资源
相似解决方案