当呈现的操作链接作为查询字符串返回时,我如何修复MVC3的路由问题

How do I fix a routing issue with MVC3 when rendered action links get returned as querystrings?

本文关键字:MVC3 问题 路由 返回 何修复 字符串 操作 链接 查询      更新时间:2023-09-26

这可能是一个简单的路由问题,但在快速谷歌之后,我没有点击我在路由上做错了什么。

当使用SignalR时,路由MapConnection会破坏默认的MVC路由渲染。

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
// default MVC
routes.MapRoute("Default", // Route name
  "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
  );
// SignalR routing
routes.MapConnection<EventConnection>("echo", "echo/{*operation}");

在这个顺序中,当SignalR js客户端连接到/echo/url时,我得到404。

如果我交换默认的MVC和SignalR路由,SignalR js客户端连接到/echo/url和SignalR函数正确,但路由被错误地重写时,呈现给视图,即

/echo?action=Index&controller=Home

我错过了什么明显的吗?我正在寻找排除回声路径的排他约束,但这似乎是沉重的,肯定有一个更简单的方法?


另外,我试过使用Regex约束,就像下面的问题一样,它不起作用。

MVC2 Routing with WCF ServiceRoute: Html。ActionLink渲染错误链接!

我最终在SignalR代码中修复了这个问题,使用下面的答案并提交了一个pull请求。

Html。当添加非mvc路由时,ActionLink会构造错误的链接

https://github.com/SignalR/SignalR/pull/19