开发者

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

With a URL like http://abc.com/myid/ab%2fcd (wh开发者_如何学Pythonere 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}

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜