2

I have a problem that if I pass a string that contain + in a query string and try to read it , it get the same string but by replacing + with empty char
For example if i pass query like ../Page.aspx?data=sdf1+sdf then in page load I read data by data = Request.QueryString["data"] it will get as below data ="sdf1 sdf"
I solve the problem by replacing any empty char with + ..

But Is there any problem that cause that ? and Is my solution by replacing empty char with + is the best solution in all cases ?

Amr Badawy
  • 7,153
  • 12
  • 47
  • 83

1 Answers1

5

Because + is the url encoded representation of space " ". If you want to preseve the plus sign in your value you will need to url encode it:

"/Page.aspx?data=" + HttpUtility.UrlEncode("sdf1+sdf")

which will produce:

/Page.aspx?data=sdf1%2bsdf

Now when you read Request.QueryString["data"] you will get what you expect.

Darin Dimitrov
  • 994,864
  • 265
  • 3,241
  • 2,902