Mvc 3 重定向路由行为异常

发布于 2024-11-17 08:30:59 字数 1083 浏览 4 评论 0原文

我已经尝试解决这个问题几天了,但没有成功。 情况是我已经将一个旧的 Web 表单站点重写为 mvc 3,并且有一堆旧的 url:s 需要重定向到新的 url:s

这就是 global.asax 中应该捕获所有请求的 2 个路由的样子到旧的 url:s

 routes.MapRoute(
            "legacyevents",
            "events/{*slug}",
            new { controller = "Redirect", action = "RedirectLegacyRoute" },
            new[] { "Web.Controllers" }
          );

            routes.MapRoute(
            "legacyarticles",
            "articles/{*slug}",
            new { controller = "Redirect", action = "RedirectLegacyRoute" },
            new[] { "Web.Controllers" }
          );

现在奇怪的是,当请求看起来像这样时,

events/randomevent__12.aspx

一切正常,但如果事件中的 E 是大写的 Events/randomevent__12.aspx asp.net 在某处向 url 添加了另一个事件单词,因此当它命中 RedirectController 时,它看起来像这样。

events/events/randomevent__12.aspx

由于几年前我编写 Web 表单应用程序时缺乏有关 SEO 的知识,许多旧 url 的传入链接都具有混合大小写: (所以我真的必须解决这个问题

应该处理文章的路由按预期工作,并且不关心传入请求网址的大小写,这使得这种情况变得如此奇怪,因为路由指向同一个 RedirectController。

任何帮助将不胜感激,如果您需要任何其他信息,我很乐意提供

最好的问候

//K

I have been trying to solve this problem for a couple of days now with no success.
The case is i have rewritten an old web forms site to mvc 3 and have a bunch of legacy url:s that need to be redirected to new url:s

This is what the 2 routes look like in global.asax that should catch all requests to old url:s

 routes.MapRoute(
            "legacyevents",
            "events/{*slug}",
            new { controller = "Redirect", action = "RedirectLegacyRoute" },
            new[] { "Web.Controllers" }
          );

            routes.MapRoute(
            "legacyarticles",
            "articles/{*slug}",
            new { controller = "Redirect", action = "RedirectLegacyRoute" },
            new[] { "Web.Controllers" }
          );

The weird thing is now that when a request looks like this

events/randomevent__12.aspx

everything works well but if the E in events is upper case Events/randomevent__12.aspx
asp.net somewhere adds another events word to the url so it looks like this when it hits the RedirectController

events/events/randomevent__12.aspx

Due to lack of knowledge about SEO when i wrote the web forms app few years back alot of incoming links to the old urls have mixed casing :( so i really have to fix this issue

The route that should handle articles works as intended and does not care about the casing of the incoming request url which which makes this case so weird, since the routes are pointed to the same RedirectController.

Any help will be appreciated and if you need any additional info i will happily provide it

best regards

//K

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

邮友 2024-11-24 08:30:59

您确实知道可以在路由匹配中使用正则表达式的全部功能吗?

请参阅此处的示例。

You do know that you can use full power of regular expressions in your route matching?

See examples here.

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