Mono asp.net MVC2 路由在 windows .net-4.0 中工作,但在 mono-2.8 中不起作用
我有一个似乎无法解决的有趣问题。
Mono 的 xsp4 似乎只对所有请求应用第一个路由。
这在 Windows 上工作:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Identities",
"{identity}",
new { controller = "Identity", action = "Index" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Static Routes",
"",
new { controller = "Home", action = "Index" }
);
}
所以当请求 /thomasvjames & Windows 中的 /Home/About 一切正常,但在 mono xsp4 中请求 /Home/About 时,它仍然映射到“Identities”路由,并且 Identity 参数设置为“Home”。
那么我是否发现了(希望存在的)单声道错误,或者我可以重新安排我的路线以使其适用于两个平台吗?
我还尝试了带有约束的包罗万象的身份路由,但无法让它在单声道中工作。
[编辑:答案] 所以这个问题的答案是,升级到最新可用的 mono 版本。 当我需要 nov 版本时,我没有使用足够新的 2.8(十月)版本。
问题解决了,下面的内容按预期工作。
I have an interesting problem that seems to be eluding me.
Mono's xsp4 only seems to be applying the first route for all requests.
This working on windows:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Identities",
"{identity}",
new { controller = "Identity", action = "Index" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Static Routes",
"",
new { controller = "Home", action = "Index" }
);
}
So when requesting /thomasvjames & /Home/About in windows everything works normally but when requesting /Home/About in mono xsp4 it still maps to the "Identities" route and the identity parameter is set to "Home".
So have i uncovered (a hopefully existing) mono bug or can i rearrange my routes to make this work for both platforms?
I've also tried a catch-all type identity route with a constraint, but was unable to get this to work in mono as well.
[Edited: The Answer]
So the answer to this question was, upgrade to the latest available build of mono.
I wasnt using a recent enough build of 2.8 (oct) when i required the nov build.
Problem solved, the below works as expected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的 MVC 书籍表明正确的方法是将更多具体条目放在较少具体条目之前,因此根据您的顺序是错误的。给出的原因正是您所描述的:它按顺序遍历列表并找到第一个匹配的条目。
通过这些更改,您的路由表应该是:`
The MVC book I have indicates the correct approach is to put MORE specific entries before LESS specific entries, so according to that your ordering is wrong. The reason given for this is exactly what you described: It traverses the list in order and finds the first entry that matches.
With these changes your routing table should be: `