开发者

ASP NET MVC Route - Not Found

开发者 https://www.devze.com 2023-03-31 06:51 出处:网络
I\'m having proble开发者_StackOverflow社区ms when using this route: routes.MapRoute(\"ProductIndex\", \"pr-{key}\", new { controller = \"Home\", action = \"Product\" });

I'm having proble开发者_StackOverflow社区ms when using this route:

routes.MapRoute("ProductIndex", "pr-{key}", new { controller = "Home", action = "Product" });

When the key contains 'pr-', the route doesn't work.

Example: http://.../pr-my-product-key-with-pr-key


Routes don't work the way you want them to work, but it's easily converted

change your route to:

routes.MapRoute(
     "ProductIndex", 
     "pr/{key}", 
      new { controller = "Home", action = "Product" });

and use:

http://.../pr/my-product-key-with-pr-key

or, if you really want to use that "way" you need to override the Initialization method of your main controller are check the link with StartWith() and redirect to the proper Controller.

0

精彩评论

暂无评论...
验证码 换一张
取 消