How to encode cookies

P

Peter Afonin

Hello:

I'm using cookies in my application. I store them like this:

Response.Cookies("Cookie_FullName").Value = customerDetails.FullName

Then I retrieve them like this:

Request.Cookies("Cookie_FullName").Value

If the name is in English - everything works OK. But when the name is in,
for instance, Cyrillic - it comes out as garbage.

Is there any way to encode the cookie, for instance, in Unicode or Cyrillic
before storing it?

I would appreciate your help.

Thank you,
 
M

Martin Dechev

Hi, Peter,

You can store the value like this:

Dim cyrillicString As String = "??????"
Response.Cookies("CookieName").Value = _
Convert.ToBase64String( _
System.Text.Encoding.Unicode.GetBytes(cyrillicString))

Then store the inBase64 string in the cookie. The reverse conversion:

Dim cookieValue As String = _
System.Text.Encoding.Unicode.GetString( _
Convert.FromBase64String( _
Request.Cookies("CookieName").Value))

Hope this helps
Martin
 
P

Peter Afonin

Thank you very much, Martin. It worked.

Peter

Martin Dechev said:
Hi, Peter,

You can store the value like this:

Dim cyrillicString As String = "??????"
Response.Cookies("CookieName").Value = _
Convert.ToBase64String( _
System.Text.Encoding.Unicode.GetBytes(cyrillicString))

Then store the inBase64 string in the cookie. The reverse conversion:

Dim cookieValue As String = _
System.Text.Encoding.Unicode.GetString( _
Convert.FromBase64String( _
Request.Cookies("CookieName").Value))

Hope this helps
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Cookies Count 2
Cookies 1
How to encode message 0
Cookies 1
cookies 1
Cookies 5
Issue with passing fetched data to POST form. How can I? 0
Encoding problem with cookies 0

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top