Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's wrong with my url encoding?
    text
    copied!<p>In my asp.net mvc application I created the following link:</p> <pre><code>http://localhost:2689/en/Formula.mvc/351702++LYS+GRONN+5G+9%252f2++fds </code></pre> <p>I get error 400 (bad request).</p> <p>I think it blocks at the %25 (forward slash).<br> What am I doing wrong?</p> <p><strong>--EDIT 3--</strong><br> I tried not encoding anything at all but rather rely on the default encoding of Url.RouteUrl().<br> It seems that this doesn't encode the "/" for some reason.<br> If I encode it myself first, I end up with the doubel encoded %252f. This gives me a bad request for some reason.. Why?!</p> <p><strong>--EDIT 2--</strong><br> I generated the last part of the URI as follows: </p> <ol> <li>Take the id.toString</li> <li>Take the HttpUtility.UrlEncode(name)</li> <li>Take the HttpUtility.UrlEncode(code)</li> <li>String.Format("{0}--{1}--{2}") with the values from the previous parts</li> <li>Add it as a parameter to Url.RouteUrl()</li> </ol> <p>After that my action gets this parameter again, splits it at -- and HttpUtility.Decode() the values back.</p> <p>I do it this way because the two last parameters are optional, but functional parameters. IF they are defined in a previous step, they have to be carried along to the other pages.<br> Less abstract: A color can have multiple names, but if a user selected it by a particular name, it should be kept throughout all the other pages.</p> <p><strong>--EDIT 1--</strong><br> It also looks like HttpUtility.UrlEncode() and Url.Encode() return different results :S </p> <p>If I don't encode the "/", it acts as a separator=>no luck there. If I encode it with Url.Encode() I end up with %2F => Code 400 If I encode it with HttpUtility.UrlEncode() I end up with %25 => code 400</p> <p>Because 400 doesn't even let it through to asp.net-mvc, the route debugger is of no use :(</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload