1

I have a webapp created using C# and asp.net. I placed a parameter value in the querystring with a plus(+) sign. But the plus sign disappear.

How can I include the plus sign(+) in the query string without disappearing?

Here I found the same question and according to it, I have used Server.UrlEncode(myqerystring) and the time of decoding Server.UrlDecode(myqerystring) but some how it always resolves to the SPACE here is watch window enter image description here

 1) Querystring after the Server.UrlEncode()
 2) Querystring after the Server.UrlDecode()

notice the space between S and R it should be +. I am new to all web development and I read other answers which says use UrlEncode and decode but it giving the same issue as before am I doing something wrong and yes the query string is automatically generated. I have no control over it.
There is other hack replace the " " or "%2b" with "+" I will go to that if I dont find any good way. So is there any good way to do this. Thanks.

Community
  • 1
  • 1
Mahesh
  • 8,694
  • 2
  • 32
  • 53

2 Answers2

3

The answer you link to just mentions using Server.UrlEncode, not Server.UrlDecode. When you read from Request.Querystring it automatically decodes the string for you. Doing it manually a second time is corrupting it and is why you're getting a space.

Ruaidhrí Primrose
  • 1,250
  • 1
  • 17
  • 22
0

You can take a look at http://msdn.microsoft.com/en-us/library/zttxte6w(v=vs.110).aspx

Although this might help

string destinationURL = "http://www.contoso.com/default.aspx?user=test";
NextPage.NavigateUrl = "~/Finish?url=" + Server.UrlEncode(destinationURL);

Regarding plus sign you can not do this as '+' sign has semantic meaning in query string Take a look at Plus sign in query string

EDIT
Have you used '+' sign while using google search. This provide different results.

Community
  • 1
  • 1
Chaturvedi Dewashish
  • 1,469
  • 2
  • 15
  • 39
  • Yes I have been using these methods and i have mentioned same question link but the issue is still if you read my description ? – Mahesh Nov 27 '14 at 07:19
  • Also if you take look at image it encoded `%2b` is ther but somehow `UrlDecode` not decoding it as `+` it is decoding it as `space` – Mahesh Nov 27 '14 at 07:20
  • Yes I know that so i am trying to decode the querystring at back end code so it should generate `+` sign but it is not generating it and I am asking why is that ? – Mahesh Nov 27 '14 at 07:23
  • + sign has a semantic meaning in the query string. It is used to represent a space. Another character that has semantic importance in the query string is & which is used to separate the various var=value pairs in the query string. Take a look at accepted answer at http://stackoverflow.com/questions/6855624/plus-sign-in-query-string – Chaturvedi Dewashish Nov 27 '14 at 07:24
  • Copied from that answer solution is "So, if you want the + sign to be preserved when a JavaScript is fetching a URL with + signs in its query parameters and a server side script would process the query parameters after URL-decoding it, `you should URL-encode the query parameters in the URL` before using issuing the HTTP get request so that `all + signs are converted to %2B's` when the request reaches the server side script. Now when the server side script `URL-decodes the query string, all %2B's gets converted back to + signs` which is what you want." and I have tried that but its not working – Mahesh Nov 27 '14 at 07:26