URLs UrlDecoded
We had an issue that some urls got UrlDecoded automatically without any apparent reason. We had to find out that some .NET methods implicitly UrlDecode the URLs even if you don’t want that.
The following methods surely decode the URLs, but there might be more:
HttpUtility.ParseQueryString(querystring)
This method returns a NameValueCollection that contains the QueryString parameters UrlDecoded.
If you want to use this method but don’t want the parameters to be decoded, you can use your own parsing algorithm. You can find one here:
http://stackoverflow.com/questions/68624/how-to-parse-a-query-string-into-a-namevaluecollection-in-net
Uri.ToString
You may expect that the result of new Uri(“url”).ToString() will equal to “url” but that is often not the case
The MSDN documentation and the sample code
also describe that the result of Uri.ToString is not the same as the original string. If you need the original, use the OriginalString property.
Uri uriAddress = new Uri("HTTP://www.Contoso.com:80/thick%20and%20thin.ht"); // The following outputs "http ://www.contoso.com/thick and thin.htm". Console.WriteLine(uriAddress.ToString());
Probably you should not use this method in your code, unless you are logging or debugging. Use the OriginalString or AbsoluteUri properties instead.
Trackbacks & Pingbacks