How can I decode an encoded URL parameter using C#?
For example, take this URL:
my.aspx?val=%2Fxyz2F
How can I decode an encoded URL parameter using C#?
For example, take this URL:
my.aspx?val=%2Fxyz2F
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;
}
Uri.UnescapeDataString
twice and got what I wanted!! :D –
Sexology Server.UrlDecode(xxxxxxxx)
System.Web.HttpServerUtilityBase
, but that should already be imported in ASP.NET MVC. –
Doig Have you tried HttpServerUtility.UrlDecode
or HttpUtility.UrlDecode
?
HttpServerUtility.UrlDecode
which is an instance method one should use HttpContext.Current.Server.UrlDecode
. –
Classmate Try:
var myUrl = "my.aspx?val=%2Fxyz2F";
var decodeUrl = System.Uri.UnescapeDataString(myUrl);
Try this:
string decodedUrl = HttpUtility.UrlDecode("my.aspx?val=%2Fxyz2F");
© 2022 - 2024 — McMap. All rights reserved.