How do I decode a URL parameter using C#?
Solution 1:
string decodedUrl = Uri.UnescapeDataString(url)
or
string decodedUrl = HttpUtility.UrlDecode(url)
Url is not fully decoded with one call. To fully decode you can call one of this methods in a loop:
private static string DecodeUrlString(string url) {
string newUrl;
while ((newUrl = Uri.UnescapeDataString(url)) != url)
url = newUrl;
return newUrl;
}
Solution 2:
Server.UrlDecode(xxxxxxxx)
Solution 3:
Have you tried HttpServerUtility.UrlDecode
or HttpUtility.UrlDecode
?
Solution 4:
Try:
var myUrl = "my.aspx?val=%2Fxyz2F";
var decodeUrl = System.Uri.UnescapeDataString(myUrl);