Make a Base64 string Url Safe

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In a asp.net site i need to make a url link like this:
http://server.com/test.aspx?base64=...Dn8WTw5zigKErw6QFxaF+wrvDksOkwqjDq1fCrsOewrc=

I've used the Convert.ToBase64String() to make the querystring parameter

But as you can see the second char is a "+". When receiving the parameter in
the test.aspx page this + gets replaced with an empty space " ".
On test.aspx i receive the parameter like this:

string test = Request.QueryString["base64"];


I've read there two articeles without finding a super nice way of making a
base64 string url safe

http://www.codeproject.com/aspnet/ScrambleQueryStrings.asp
http://www.codeproject.com/aspnet/EncodedUrlBuilder.asp
 
Rasmus said:
Yes: "How do i make a Base64 string Url Safe?"

I'll tell you what I do: I don't use Base64. I use a hexadecimal
encoding, using only 0-9 and A-F. It's more verbose than Base64, but it
always works.

Alternatively, you can swap out the characters that don't work well in
URLs ('/' and '+') with URL encoding, i.e. '%XX' for the values for /
and + (%2F and %2B), or use URI.EscapeDataString() etc.

-- Barry
 
just use server.urlencode on the base 64 string

afaik request.querystring automaticly performs a urldecode , however if it
isn`t use server .urldecode on the receiving part to get the base64 string
back


regards

Michel Posseth .
 
Rasmus said:
I've used the Convert.ToBase64String() to make the querystring parameter

Use "UrlEncode" to encode the URL prior to sending it back to the client.
 
Back
Top