C# 使用特殊&;或+;查询参数值中的字符

C# 使用特殊&;或+;查询参数值中的字符,c#,javascript,jquery,url,string-decoding,C#,Javascript,Jquery,Url,String Decoding,我在解码带有参数的Base64编码URL时遇到了这个困难 eg: http://www.example.com/Movements.aspx?fno=hello&vol=Bits & Pieces 我的预期结果应该是: 你好 vol=比特和碎片 #Encoding: //JAVASCRIPT var base64 = $.base64.encode("&fno=hello&vol=Bits & Pieces"); wind

我在解码带有参数的Base64编码URL时遇到了这个困难

eg: http://www.example.com/Movements.aspx?fno=hello&vol=Bits & Pieces
我的预期结果应该是: 你好 vol=比特和碎片

#Encoding:
//JAVASCRIPT                
var base64 = $.base64.encode("&fno=hello&vol=Bits & Pieces");
window.location.replace("Movements.aspx?" + base64);

#Decoding c#
string decodedUrl = System.Text.Encoding.ASCII.GetString(Convert.FromBase64String(Request.Url.Query.Replace("?", ""))); // Replace is used to remove the ? part from the query string. 
string fileno = HttpUtility.ParseQueryString(decodedUrl).Get("fno");
string vol = HttpUtility.ParseQueryString(decodedUrl).Get("vol");
实际结果: 你好 vol=位

我搜索了stackoverlow,似乎需要添加一个自定义算法来解析解码的字符串。但是,由于实际的URL比本例中显示的更复杂,我认为最好向专家寻求另一种解决方案


谢谢阅读

如果URL编码正确,您将:

%26是&
空间将被替换为+

在JS中,使用
escape
对url进行正确编码

[编辑]


使用
encodeURIComponent
而不是
escape
,因为正如萨尼·赫图宁所说,“escape”已被弃用。对不起

您的查询字符串需要正确编码。Base64不是正确的方法。改用
encodeURIComponent
。您应该分别对每个值进行编码(尽管示例中的大多数部分不需要):

那么你就不需要用C#进行Base64解码了


escape
自ECMAScript 3以来已被弃用,不应再使用。谢谢Sani。你说得对!我对整个查询部分进行了编码。你的例子触发了我的错误行为!Base64在这里实际上是不必要的,但由于它在整个项目中都实现了,所以我也可以使用它。
var qs = "&" + encodeURIComponent("fno") + "=" + encodeURIComponent("hello") + "&" + encodeURIComponent("vol") + "=" + encodeURIComponent("Bits & Pieces");
// Result: "&fno=hello&vol=Bits%20%26%20Pieces"
var qs = HttpUtility.ParseQueryString(Request.Url.Query.Replace("?", ""));
var fileno = qs.Get("fno");
var vol = sq.Get("vol");