0

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?

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, that's it. Don't know why that didn't occur to me in the first place.
1

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)

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.