views:

344

answers:

3

I am passing an object from one asp.net page to another. I'm encoding the object as a Base64 string and passing it as a POST parameter. However, when the receiving page reads the POST value, if there is a + sign in the Base64 string, it is being replaced with a line break. For example:

 ...AABDEDS+DFEAED...

becomes

 ...AABDEDS
 DFEAED...

I compared the Base64 string immediately after encoding in the sending page to the string immediately before decoding in the receiving page and that is the only difference. I tried HtmlEncoding() the base64 string prior to writing it to the request stream, but that had no effect, so it seems to be an issue on the receiving end.

Any ideas?

+2  A: 

Use UrlEncode. The + is a reserved character and needs to be encoded.

Rex M
Yep, that's it. Don't know why that didn't occur to me in the first place.
NYSystemsAnalyst
+1  A: 

When you pass the base64 string in the parameter, you need to URL Encode it (so the characters come across properly). Use:

System.Web.HttpServerUtility.UrlEncode(base64String);

HttpServer.UrlEncode Method (String)(System.Web)

Justin Niessner
+1 for the right answer, but Rex got there first. Thanks.
NYSystemsAnalyst
A: 

the + symbol is a special URL character that on it's own evaluates to a space in the URL.

You'll need to Server.URLEncode your base64 string on one side (which will turn the Plus into a %2B and Server.URLDecode it on the other side

Eoin Campbell