2
VerifyEmail.aspx?key=KMSO+tLs5zY=&val=ALKXZzxNxajUWVMaddKfPG/FcFD111CD

Request.QueryString["key"].ToString() gives me "KMSO tLs5zY="

i want key value "KMSO+tLs5zY="

sangram parmar
  • 8,462
  • 2
  • 23
  • 47

2 Answers2

4

If you can modify the url parameter, you can encode the values using the HttpUtility.UrlEncode method, for example:

string url = "VerifyEmail.aspx?key=" + HttpUtility.UrlEncode("KMSO+tLs5zY=");

Another method is to use Base64 encoding

string url = "VerifyEmail.aspx?key=" + EncodeTo64("KMSO+tLs5zY=");

and decoding the value reading the querystring

String value = DecodeFrom64(Request["key"]);

the code for the EncodeTo64 and DecodeFrom64 is available in this article http://arcanecode.com/2007/03/21/encoding-strings-to-base64-in-c/

Massimo Zerbini
  • 3,125
  • 22
  • 22
  • It's strange, but if you have problem with special chars you can use Base64 encoding for parameters. In this article there is an example of Base64 encoding and decoding: http://arcanecode.com/2007/03/21/encoding-strings-to-base64-in-c/ remember to decode the value before use it. – Massimo Zerbini Jun 12 '13 at 08:54
-2

Do not use %2B instead of + when producing url.

And if you get %2B's itself when requesting, do not try to replace it using

Request.QueryString["key"].ToString().Replace("%2B","+")

Use HttpUtility class' UrlEncode() method:

HttpUtility.UrlEncode("KMSO+tLs5zY=")

(:

zkanoca
  • 9,664
  • 9
  • 50
  • 94