简体   繁体   中英

How do I decode a URL parameter using C#?

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;
}
Server.UrlDecode(xxxxxxxx)

尝试这个:

string decodedUrl = HttpUtility.UrlDecode("my.aspx?val=%2Fxyz2F");

Try:

var myUrl = "my.aspx?val=%2Fxyz2F";
var decodeUrl = System.Uri.UnescapeDataString(myUrl);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM