如何获得ASP.NET MVC匹配点(QUOT;")在路由结束字符? [英] How to get ASP.NET MVC to match dot (".") character at the end in a route?

查看:80
本文介绍了如何获得ASP.NET MVC匹配点(QUOT;")在路由结束字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.NET MVC对待点字符作为一个字面的路线久时间。然而,如果点是在给定的路线部分的末端不匹配的路线。

ASP.NET MVC treats dot character as a literal for routes for a long time. However it doesn't match the route if the dot is at the end of the given route part.

由于路线 {控制器} / {行动} / {ID} MVC匹配这些:

Given the route {controller}/{action}/{id} MVC matches these:

http://test/somecontroller/someaction/some.id
http://test/somecontroller/someaction/....some.id

但不是这些:

http://test/somecontroller/someaction/someid.
http://test/somecontroller/someaction/someid...

我的要求是具有小点的任意数量的在ID部分的任何地方。有没有办法来解决这个周围或者是一个已知的情况下,我们需要避免?在我看来,一个MVC 2的bug。

My requirement is to have arbitrary number of dots anywhere in the id section. Is there a way to work this around or is it a known situation that we need to avoid? It seems to me an MVC 2 bug.

P.S。你也可以通过添加点来在不同的地方的URL字符串问题重现StackOverflow上相同的行为。

P.S. You can also reproduce the same behavior on StackOverflow by adding dots to the question string in the URL at different places.

编辑:对不起,这似乎是重复的<一个href=\"http://stackoverflow.com/questions/429963/the-resource-cannot-be-found-error-when-there-is-a-dot-at-the-end-of-the-url\">http://stackoverflow.com/questions/429963/the-resource-cannot-be-found-error-when-there-is-a-dot-at-the-end-of-the-url 。之前,我找不到它自己。

Sorry this seems to be duplicate of http://stackoverflow.com/questions/429963/the-resource-cannot-be-found-error-when-there-is-a-dot-at-the-end-of-the-url . I couldn't find it myself before.

推荐答案

如果您使用的是.NET 4.0,你可以在你的web.config的system.web节设置此标志,它会被允许:

If you are using .NET 4.0, you can set this flag in the system.web section of your web.config and it will be allowed:

<httpRuntime relaxedUrlToFileSystemMapping="true" />

我测试过它和它的作品。 哈克有它的一个解释。

这篇关于如何获得ASP.NET MVC匹配点(QUOT;&QUOT;)在路由结束字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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