简体   繁体   English

Request.QueryString没有返回正确的值

[英]Request.QueryString not returning the correct value

I'm using AES encryption for the values of a URL. 我将AES加密用于URL值。 I've sampled it here with only one parameter to demonstrate the problem: 我在这里仅用一个参数对其进行了采样,以演示该问题:

http://localhost:12345/pagename?id=ha3bEv8A%2ffs0goPGeO6NPQ%3d%3d HTTP://本地主机:12345 /页面名ID = ha3bEv8A%2ffs0goPGeO6NPQ%3D%3D

Request.QueryString["id"] returns "ha3bev8a/fs0gopgeo6npq==" which clearly does not match the value of the encrypted ID. Request.QueryString["id"]返回"ha3bev8a/fs0gopgeo6npq==" ,这显然与加密ID的值不匹配。 Is something tripping up QueryString? 有什么绊倒QueryString吗?

You are getting a URL-encoded query string, which Request.QueryString["id"] seems to decode for you. 您将获得一个URL编码的查询字符串,其中Request.QueryString["id"]似乎可以为您解码。 You could always just re-encode it: 您总是可以重新编码它:

string decodedId = Request.QueryString["id"];
string reEncodedId = HttpUtility.UrlEncode(decodedId);

The value you are seeing is in fact correct. 您所看到的值实际上是正确的。 What might be confusing you, is in the way it is presented. 呈现方式可能会使您感到困惑。 The id value in the URL is encoded in URL Encoding. URL中的id值以URL编码进行编码。 Some characters have to be encoded in the URL String in a different way, as they are special characters that sometimes can mess up the way the string is interpreted if they aren't encoded properly. 有些字符必须以不同的方式编码在URL字符串中,因为它们是特殊字符,如果它们的编码不正确,有时会弄乱字符串的解释方式。

For example, in the query string you provided: http://localhost:12345/pagename?id=ha3bEv8A%2ffs0goPGeO6NPQ%3d%3d 例如,在您提供的查询字符串中: http:// localhost:12345 / pagename?id = ha3bEv8A%2ffs0goPGeO6NPQ%3d%3d

The %2f characters are a way to encode the '/' character, while %3d is a way to encode the '=' character. %2f字符是对'/'字符进行编码的方式,而%3d是对'='字符进行编码的方式。

When you get the value by getting Request.QueryString["id"] , it is decoding it back from an URL Encoded string to raw text. 当您通过获取Request.QueryString [“ id”]来获取值时,它会将其从URL编码的字符串解码回原始文本。

Check this page for more reference. 检查此页面以获取更多参考。 https://www.w3schools.com/tags/ref_urlencode.asp https://www.w3schools.com/tags/ref_urlencode.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM