Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get asp.net to not automatically unescape escaped forward-slashes in URLs?

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?

like image 257
Dan P Avatar asked Mar 17 '11 02:03

Dan P


1 Answers

An easy solution is to use a catch-all token, e.g. {controller}/{action}/{*id}

like image 101
Max Toro Avatar answered Nov 03 '22 18:11

Max Toro