How do I decode a URL parameter using C#?

2019-01-03 02:40发布

How can I decode an encoded URL parameter using C#?

For example, take this URL:

my.aspx?val=%2Fxyz2F

5条回答
兄弟一词,经得起流年.
3楼-- · 2019-01-03 02:59

Try string s = System.Uri.UnescapeDataString(here);

查看更多
老娘就宠你
4楼-- · 2019-01-03 03:02

Try this:

string decodedUrl = HttpUtility.UrlDecode("my.aspx?val=%2Fxyz2F");
查看更多
在下西门庆
5楼-- · 2019-01-03 03:03
Server.UrlDecode(xxxxxxxx)
查看更多
\"骚年 ilove
6楼-- · 2019-01-03 03:06
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;
}
查看更多
登录 后发表回答