How do I decode a URL parameter using C#?

只愿长相守 提交于 2019-11-26 01:15:49

问题


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

For example, take this URL:

my.aspx?val=%2Fxyz2F

回答1:


Server.UrlDecode(xxxxxxxx)



回答2:


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;
}



回答3:


Have you tried HttpServerUtility.UrlDecode or HttpUtility.UrlDecode?




回答4:


Try this:

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



回答5:


Try:

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


来源:https://stackoverflow.com/questions/1405048/how-do-i-decode-a-url-parameter-using-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!