asp .net查询字符串编码和解码

Var*_*rma 5 asp.net url-encoding urldecode query-string

我在我的网络浏览器中输入以下网址,然后按Enter键.

http://localhost/website.aspx?paymentID=6++7d6CZRKY%3D&language=English
Run Code Online (Sandbox Code Playgroud)

现在在我的代码中,当我做HttpContext.Current.Request.QueryString ["paymentID"]时,

我得到6 7d6CZRKY =

但是当我做HttpContext.Current.Request.QueryString.ToString()时,我看到以下内容:

paymentID = 6 ++ 7d6CZRKY%3D&语言=英语

我想要提取用户在Web浏览器URL中键入的实际付款ID.我不担心网址是否编码.因为我知道这里有一个奇怪的东西%3D和+同时签名!但我确实需要实际的+号.当我做HttpContext.Current.Request.QueryString ["paymentID"]时,不知何故它被解码到空间.

我只想提取用户输入的实际付款ID.最好的方法是什么?

谢谢.

Mik*_*Dev 6

您需要首先使用URLEncode()对URL进行编码.URL中的+等于空格,因此需要编码为%2b.

string paymentId = Server.UrlEncode("6++7d6CZRKY=");
// paymentId = 6%2b%2b7d6CZRKY%3d
Run Code Online (Sandbox Code Playgroud)

现在

string result = Request.QueryString["paymentId"].ToString();
//result = 6++7d6CZRKY=
Run Code Online (Sandbox Code Playgroud)

然而

string paymentId = Server.UrlEncode("6  7d6CZRKY=");
//paymentId looks like you want it, but the + is a space -- 6++7d6CZRKY%3d

string result = Request.QueryString["paymentId"].ToString();
//result = 6 7d6CZRKY=
Run Code Online (Sandbox Code Playgroud)