Search code examples
c#urlasp.net-web-apiencodingasp.net-web-api-routing

WebApi / Routing with URL Encoding


Related to this: URL-encoded slash in URL

I used Mehrdad Afshari's answer (wildcard route param) which works mostly! However, multiple slashes are converted to a single slash.

My route is resource/{*url}

With GET resource/abc%2fdef my controller method is called with abc/def.

With GET resource/abc%2f%2f%2f%2fdef my controller method is again called with abc/def. The extra slashes are lost.


Solution

  • Did you see this stackoverflow question plus solution:

    URL-encoded slash in URL

    this directs you to that post http://gathadams.com/2009/01/06/allowing-special-characters-forward-slash-hash-asterisk-etc-in-aspnet-mvc-urls/

    Phil haacked responded like this http://haacked.com/archive/2008/04/10/upcoming-changes-in-routing.aspx#68032