我正在传递一个加密的 URL 字符串:
Default.aspx?S3tLlnIKKzE%3d
我想将该 URL 字符串传递回变量中的 ASPX 页面。
protected string qs = string.Empty;
NameValueCollection qscollstring = HttpContext.Current.Request.QueryString;
qs = qscollstring[0];
哪个返回:S3tLlnIKKzE=
qscollstring[0]中的值是正确的:S3tLlnIKKzE%3d
我知道问题出在 URL 编码上,但我找不到保持字符串原样的方法。
看来从qscollstring[0]赋值是:S3tLlnIKKzE%3d
字符串更改值:S3tLlnIKKzE=
我需要留下来:S3tLlnIKKzE%3d
最佳答案
使用HttpUtility.UrlEncode
方法对字符串进行编码。
qs =HttpUtility.UrlEncode(qscollstring[0]);
关于c# - 使用 NameValueCollection 将 QueryString 转换为 URL-Encode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8936826/