【问题标题】:ASP.NET MVC Routing HelpASP.NET MVC 路由帮助
【发布时间】:2011-08-17 04:05:52
【问题描述】:

我有以下网址:

http://localhost/About
http://localhost/Contact
http://localhost/Shop
http://localhost/Shop/ListProducts/{CategoryID}/{CategoryName}
http://localhost/Shop/Checkout
http://localhost/Customer
http://localhost/Customer/Edit
http://localhost/Customer/ChangePassword
http://localhost/Authentication/LogOn
http://localhost/Authentication/LogOff

还有以下地图:

routes.MapRoute("Authentication", "Authentication/{action}", New With {.controller = "Authentication", .action = "Index"})
routes.MapRoute("Customer", "Customer/{action}", New With {.controller = "Customer", .action = "Index"})
routes.MapRoute("Shop", "Shop/{action}/{CategoryID}/{CategoryName}", New With {.controller = "Shop", .action = "Index", .CategoryID = UrlParameter.Optional, .CategoryName = UrlParameter.Optional})
routes.MapRoute("Main", "{action}", New With {.controller = "Main", .action = "Index"})
routes.MapRoute("Default", "{controller}/{action}/{id}", New With {.controller = "Main", .action = "Index", .id = UrlParameter.Optional})

虽然这似乎可行,但我需要一种方法来处理带有 404 的未知路由/url。

我在这里查看了一些示例,但似乎无法使它们起作用。

另外,这些路线看起来正确吗?我在正确的轨道上吗?

谢谢

【问题讨论】:

    标签: asp.net-mvc-3 routing


    【解决方案1】:

    您走在正确的轨道上 - 请参阅此帖子以处理所有 404。

    How can i make a catch all route to handle '404 page not found' queries for ASP.NET MVC?

    特别是这部分

    路线.MapRoute( “404页面不存在”, "{*url}", 新的{控制器=“StaticContent”,动作=“PageNotFound”} );

    【讨论】:

      猜你喜欢
      • 2011-01-31
      • 1970-01-01
      • 1970-01-01
      • 2010-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多