开发者

How to get ASP.NET MVC to match dot (".") character at the end in a route?

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.

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

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

But not these:

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

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. You can also reproduce the same behavior on StackOverflow by adding dots to the question string in the URL at different places.

EDIT: Sorry this seems to be duplicate of "The resource cannot be found." error when there is a "dot&q开发者_如何学Pythonuot; at the end of the url . I couldn't find it myself before.


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" />

I've tested it and it works. Haack has an explanation of it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜