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?
Edit: added code with UrlEncode
string str = Server.UrlEncode(Requery.QueryString["new"]);
+ 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.
Most server side scripts would decode the query parameters before using them, so that a
+ gets properly converted to a space. Now, if you want a literal
+ to be present in the query string, you need to specify
+ sign in the query string is URL-decoded to a space.
%2B in the query string is URL-decoded to a + sign.
See the difference between
In the above examples, Google's server script is URL-decoding the query parameters and then using them to do the search.
URL-encoding is nothing but
% sign followed by the hex-code of the special character. For example, we know that the hex code of
A is 0x41 (decimal: 65). Try this:
Hope this makes URL-encoding clear.
So, if you want the
+ 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.
var encodedURL = "http://example.com/foo.php?var=" + encodeURIComponent(param);
You should URLEncode your query string values to make sure any special characters are not lost.
I alter my previous statement so no one gets confused!
Create your url using the Server.UrlEncode. e.g.
string myUrl = "http://myurl?param1=" + Server.UrlEncode("my+param+1");
Other simple way is,
Request.Url.ToString().Substring(Request.Url.ToString().IndexOf("=") + 1) assuming that my URL is,
before send you parameter, you need check if the parameter contains plus sign, if have you need replace to one flag, for example: the parameter is: klasjdlkasd+djid3223 can you replace: klasjdlkasdFLAGdjid3223
and when you go convert, you need replace angain
Try this, it works for me:
Add this line in Decrypt Funcation:
strText = strText.Replace(" ", "+");
Look at HTML URL Encoding Reference
You need to Encode the + sign - It's value should be %2B
The solution is to ALWAYS include .Replace(" ", "+") when you request querystring
string s = Request.QueryString["id"].Trim().Replace(" ", "+");
©2020 All rights reserved.