views:

104

answers:

1

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 ?

+2  A: 

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
thanks darin ..
Space Cracker