3

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

3 Answers 3

4

Use HttpUtility.UrlEncode method to encode the string.

 qs =HttpUtility.UrlEncode(qscollstring[0]);
Sign up to request clarification or add additional context in comments.

Comments

0

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; 

Comments

0

Like me if you are searching for the reverse .. use

qs =HttpUtility.UrlDecode("S3tLlnIKKzE%3d");

to get back S3tLlnIKKzE=

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.