Reputation: 24488
I am passing an encrypted URL string:
Default.aspx?S3tLlnIKKzE%3d
I want to pass that URL string back into the ASPX page in a variable.
protected string qs = string.Empty;
NameValueCollection qscollstring = HttpContext.Current.Request.QueryString;
qs = qscollstring[0];
Which return : S3tLlnIKKzE=
The value in qscollstring[0] is correct: S3tLlnIKKzE%3d
I understand the problem is URL-Encoding, but I cannot find a way to keep the string as is.
It seems that assigning the value from qscollstring[0] is: S3tLlnIKKzE%3d
to string changes the value : S3tLlnIKKzE=
I need to to stay: S3tLlnIKKzE%3d
Upvotes: 3
Views: 5212
Reputation: 9630
Like me if you are searching for the reverse
.. use
qs =HttpUtility.UrlDecode("S3tLlnIKKzE%3d");
to get back S3tLlnIKKzE=
Upvotes: 0
Reputation: 4841
You can also pull the value from the Uri of the current URL without having to Encode the value.
Sample:
Uri u = new Uri("http://localhost.com/default.aspx?S3tLlnIKKzE%3d");
string q = u.Query;
And part of your page:
string q = !String.IsNullOrEmpty(Request.Url.Query) && Request.Url.Query.Length > 1 ? Request.Url.Query.Substring(1) : Request.Url.Query;
Upvotes: 0
Reputation: 94643
Use HttpUtility.UrlEncode
method to encode the string.
qs =HttpUtility.UrlEncode(qscollstring[0]);
Upvotes: 4