为什么这个不路由到默认操作?

发布于 2024-12-26 01:42:51 字数 642 浏览 2 评论 0原文

所以我映射了这条路线:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栖竹 2025-01-02 01:42:51

您在 global.asax 中定义路由的顺序是什么,这可能与问题有关,但我最初的猜测是它与默认路由匹配,

controller: en-GB  
action: Solutions
id : SolutionA

您可以做的是在您的路由上设置某种正则表达式匹配将您的语言从“默认”路由中排除的路由?尝试此链接以获取有关使用正则表达式进行路由过滤的更多信息 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

controller: en-GB  
action: Solutions
id : SolutionA

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文