Answers:
string decodedUrl = Uri.UnescapeDataString(url)
要么
string decodedUrl = HttpUtility.UrlDecode(url)
一次呼叫无法完全解码网址。要完全解码,您可以循环调用以下方法之一:
private static string DecodeUrlString(string url) {
string newUrl;
while ((newUrl = Uri.UnescapeDataString(url)) != url)
url = newUrl;
return newUrl;
}
Uri.UnescapeDataString
两次,得到了我想要的!:D
HttpServerUtility.UrlDecode
作为实例方法,应使用HttpContext.Current.Server.UrlDecode
。
尝试:
var myUrl = "my.aspx?val=%2Fxyz2F";
var decodeUrl = System.Uri.UnescapeDataString(myUrl);