失败的ASP.NET MVC路线。这是一个错误或角呢? [英] Failing ASP.NET MVC route. Is this a bug or corner case?

查看:146
本文介绍了失败的ASP.NET MVC路线。这是一个错误或角呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET MVC 3应用程序,用户可以发布沿线的建议喇嘛喇嘛的会更好,如果的亚达内容十分重要。
对于建议的详细页面我已经定义了一个不错的搜索引擎友好的路线如下:

I have an ASP.NET MVC 3 application where users can post suggestions along the lines of "bla bla would be better if yada yada yada". For the suggestion detail page I have defined a nice SEO friendly route as follows:

routes.MapRoute(null, "suggestion/{id}/{it}/would-be-better-if-{if}", 
    new { controller = "suggestion", action = "details" });

正如你可以看到我想要的会更好,如果是固定的组成部分。

As you can see I want the "would be better if" part to be fixed.

这条路线完全适用于任何旧的建议,并产生像建议/ 5 /此站点的链接/想成为,更好,如果-IT-有-A-iphone的应用程序,并单击链接实际上请求相应的详细信息页面。

This route works perfectly for any old suggestion and generates links like suggestion/5/this-site/would-be-better-if-it-had-a-iphone-application, and clicking on the link actually requests the appropriate detail page.

我的一个朋友,谁具有讽刺意味的​​恰好是一个测试仪,成功地,不由自主地,张贴,实际上打破了路线的建议:此网站会更好,如果会更好,如果总是对齐中间的。结果
这一建议所产生的链接
<$c$c>/suggestion/84/this-site/would-be-better-if-would-be-better-if-was-always-alligned-in-the-middle.

A friend of mine, who ironically happens to be a tester, has managed to, involuntarily, post a suggestion that actually breaks the route: "This site would be better if 'would be better if' was always aligned in the middle".
The link generated for this suggestion is /suggestion/84/this-site/would-be-better-if-would-be-better-if-was-always-alligned-in-the-middle.

我曾尝试菲尔哈克的路由调试并已经证实,该航线将实际工作,直到建议/ 84 /本网站/想成为,更好,如果-想成为,更好,如果 - ,所以第二个想成为,更好,如果实际上是接受;之后添加任何实际上将导致URL不匹配任何路线的(感谢奥马尔 - 请参阅评论 - 求助)

I have tried Phil Haack's Routing Debugger and have confirmed that the route will actually work up until suggestion/84/this-site/would-be-better-if-would-be-better-if-, so the second "would-be-better-if" is actually accepted; adding anything after that will actually cause the url not to match any route (thanks to Omar -see comments- for help).

请记住,我真的不希望更改路由定义,因为我认为这是一样好,我可以管理这种情况下,搜索引擎优化,明智的。

Please bear in mind that I really don't want to change the route definition since I think it is as good as I can manage for this case, SEO-wise.

因此​​, 怎么来的有文本等于航线$ P $的固定部分pvents从路由匹配的联系? 为什么是路由破?

So, how come having text equal to the fixed part of the route prevents the link from matching the route? why is the route breaking?

我其实rahter更感兴趣的是在为什么,因为我相信理解为什么会导致一个颇为有趣的问题的解决,或者至少有正确的认识。

I am actually rahter more interested in the why, as I believe understanding the why will lead to a solution or at least a proper understanding of a rather interesting problem.

推荐答案

这看起来像<一个一个欺骗href=\"http://stackoverflow.com/questions/4318373/asp-net-routing-using-delimeters-other-than-slash\">ASP.NET路由:令牌之间立即子段,和路由值与从文字子段这是错误的一个更简单版本的字符。我建议你​​关闭有利于那一个这一个。

This looks like a dupe of ASP.NET routing: Literal sub-segment between tokens, and route values with a character from the literal sub-segment which is a much simpler version of the bug. I'd recommend closing this one in favor of that one.

我回答了这个问题。

这篇关于失败的ASP.NET MVC路线。这是一个错误或角呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆