My map:
routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with params new { controller = "Home", action = "Index", id = "" } // Param defaults );
If I use the URL http://localhost:5000/Home/About/100%2f200 , then there is no corresponding route. I change the url to http://localhost:5000/Home/About/100 , after which the route maps again.
Is there an easy way to work with parameters containing slashes? Other escape values ββ(space %20 ) seem to work.
EDIT:
For coding, Base64 works for me. This makes the URL ugly, but OK for now.
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)); } }
EDIT1:
In the end, it turned out that the best way is to save a nicely formed string for each item I need to select. This is much better, because now I only encode values ββand never decrypt them. All special characters become "-". Many of my db tables now have an extra "url" column. The data is pretty stable, which is why I can go this route. I can even check if the data in the "URL" is unique.
EDIT2:
Also watch out for the space character. It looks fine on a VS-integrated web server, but different from iis7. Correct url encodes a space character
c # asp.net-mvc urlencode asp.net-mvc-routing
Mathias F Feb 26 '09 at 17:58 2009-02-26 17:58
source share