Request.QueryString Replace + with Empty Char

If I pass a string that contains + in a query string and try to read it, i will get the same string by replacing + with empty char.

For example if i pass query string like
Page.aspx?data=abc+1002
while reading Request.QueryString["data"] it gives me below value data ="abc 1002".

Reason behind this is + is the url encoded representation of space " "

In order to overcome this problem you will need to encode your url as below
Page.aspx?data=" + HttpUtility.UrlEncode("abc+1002")

which will produce:
Page.aspx?data=abc%2b1002
To get your original data back you need to decode the same as below
HttpUtility.UrlDecode("abc%2b1002")
which will give you abc+1002.
 

0 comments:

Twitter Delicious Facebook Digg Stumbleupon Favorites More