Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

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" at the end of the url . I couldn't find it myself before.

like image 288
Sedat Kapanoglu Avatar asked Aug 22 '10 12:08

Sedat Kapanoglu


1 Answers

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.

like image 119
bkaid Avatar answered Dec 22 '22 16:12

bkaid