With a URL like http://abc.com/myid/ab%2fcd (where the %2f is an escaped slash), asp.net will unescape the %2f so that from my application's perspective (and from asp.net mvc's perspective) the URL is: http://abc.com/myid/ab/cd
Since my application uses asp.net mvc, this behavior can easily cause problems with routing if I want to have a route specified something like "/myid/{id}" since asp.net's unescaping will cause that route not to match.
According to the answer to this question: URL-encoded slash in URL and according to this msdn page: http://msdn.microsoft.com/en-us/library/ee656542.aspx the solution (in .Net 4.0) is to put the following in your web.config:
<uri>
<schemeSettings>
<add name="http" genericUriParserOptions="DontUnescapePathDotsAndSlashes"/>
</schemeSettings>
</uri>
But I can't actually get it to work - the "%2f" is still being automatically unescaped into "/". Does anyone know why the config setting might not be working for me, or have any other suggestions?
An easy solution is to use a catch-all token, e.g. {controller}/{action}/{*id}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With