Note that there are some explanatory texts on larger screens.

plurals
  1. POURL-encoded slash in URL
    primarykey
    data
    text
    <p>My Map is:</p> <pre><code>routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with params new { controller = "Home", action = "Index", id = "" } // Param defaults ); </code></pre> <p>If I use the URL <code>http://localhost:5000/Home/About/100%2f200</code> there is no matching route. I change the URL to <code>http://localhost:5000/Home/About/100</code> then the route is matched again.</p> <p>Is there any easy way to work with parameters that contain slashes? Other escaped values (space <code>%20</code>) seem to work.</p> <p>EDIT:</p> <p>To encode Base64 works for me. It makes the URL ugly, but that's OK for now.</p> <pre><code>public class UrlEncoder { public string URLDecode(string decode) { if (decode == null) return null; if (decode.StartsWith("=")) { return FromBase64(decode.TrimStart('=')); } else { return HttpUtility.UrlDecode( decode) ; } } public string UrlEncode(string encode) { if (encode == null) return null; string encoded = HttpUtility.PathEncode(encode); if (encoded.Replace("%20", "") == encode.Replace(" ", "")) { return encoded; } else { return "=" + ToBase64(encode); } } public string ToBase64(string encode) { Byte[] btByteArray = null; UTF8Encoding encoding = new UTF8Encoding(); btByteArray = encoding.GetBytes(encode); string sResult = System.Convert.ToBase64String(btByteArray, 0, btByteArray.Length); sResult = sResult.Replace("+", "-").Replace("/", "_"); return sResult; } public string FromBase64(string decode) { decode = decode.Replace("-", "+").Replace("_", "/"); UTF8Encoding encoding = new UTF8Encoding(); return encoding.GetString(Convert.FromBase64String(decode)); } } </code></pre> <p>EDIT1:</p> <p>At the end it turned out that the best way was to save a nicely formated string for each item I need to select. Thats much better because now I only encode values and never decode them. All special characters become "-". A lot of my db-tables now have this additional column "URL". The data is pretty stable, thats why I can go this way. I can even check, if the data in "URL" is unique.</p> <p>EDIT2:</p> <p>Also watch out for space character. It looks ok on VS integrated webserver but is different on iis7 <a href="https://stackoverflow.com/questions/1651711/properly-url-encode-space-character">Properly url encode space character</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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