为什么这个不路由到默认操作?
所以我映射了这条路线:
routes.MapRoute(
"Solutions",
"{lang}/Solutions/{controller}/{action}",
new { lang="en-US", controller = "WhatWeDo", action = "Index"}
);
当我转到“
/en-GB/Solutions/SolutionA/Index/
它路由得很好,但
/en-GB/Solutions/SolutionA/
根本不路由。但是,如果我取出lang参数,那么路由看起来像
routes.MapRoute(
"Solutions",
"Solutions/{controller}/{action}",
new { controller = "WhatWeDo", action = "Index"}
);
我转到
/Solutions/SolutionA/
它路由得很好。任何我想不必一直为这条路线指定默认操作。
So I have this route mapped:
routes.MapRoute(
"Solutions",
"{lang}/Solutions/{controller}/{action}",
new { lang="en-US", controller = "WhatWeDo", action = "Index"}
);
When I go to"
/en-GB/Solutions/SolutionA/Index/
It routes just fine, but
/en-GB/Solutions/SolutionA/
Doesn't route at all. However, if I take out the lang parameter, so the route looks like
routes.MapRoute(
"Solutions",
"Solutions/{controller}/{action}",
new { controller = "WhatWeDo", action = "Index"}
);
and I go to
/Solutions/SolutionA/
It routes just fine. Any ideas? I'd like to not have to specify the default action all the time for this route. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在 global.asax 中定义路由的顺序是什么,这可能与问题有关,但我最初的猜测是它与默认路由匹配,
您可以做的是在您的路由上设置某种正则表达式匹配将您的语言从“默认”路由中排除的路由?尝试此链接以获取有关使用正则表达式进行路由过滤的更多信息 http://www.iridescent.no/post/Defining-Routes-using-Regular-Expressions-in-ASPNET-MVC.aspx
What order are you defining your routes in global.asax, this could have something to with the issue but my initial guess is that it's matching the default route as such
What you might be able to do is setup some sort of regular expression matching on your routes to exclude your language from the "default" route? Try this link for more information about using regex for route filtering http://www.iridescence.no/post/Defining-Routes-using-Regular-Expressions-in-ASPNET-MVC.aspx