473,396 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to encode cookies

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,

--
Peter Afonin
Nov 18 '05 #1
2 3772
Hi, Peter,

You can store the value like this:

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

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
"Peter Afonin" <pv*@speakeasy.net> wrote in message
news:ef**************@TK2MSFTNGP09.phx.gbl...
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,

--
Peter Afonin

Nov 18 '05 #2
Thank you very much, Martin. It worked.

Peter

"Martin Dechev" <de*******@hotmail.com> wrote in message
news:ua**************@tk2msftngp13.phx.gbl...
Hi, Peter,

You can store the value like this:

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

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
"Peter Afonin" <pv*@speakeasy.net> wrote in message
news:ef**************@TK2MSFTNGP09.phx.gbl...
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,

--
Peter Afonin


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Brian Burgess | last post by:
Hi all, Anyone know of any special issues with storing cookies with ASP? I'm trying this with two browsers: One is IE 6.0 with cookies set to 'prompt'. This has been working properly as any...
20
by: Brian Burgess | last post by:
Hi all, Anyone know if this is possible? If so, on which page would the cookie be? .. On the page calling a function defined in the include file? thanks in advance.. -BB
6
by: Mark | last post by:
Hi... I've come across some weird bug with Response.Cookies. Or maybe it will be called "by design" but for the life of me I can't figure out what purpose it would serve. If you're setting a...
4
by: Newbie | last post by:
How would I modify this form to encode *all* the characters in the 'source' textarea to the '%xx' format & place result code into the 'output' textarea? (cross browser compatable) Any help is...
3
by: Peter | last post by:
Hi, I try to make up a javascript string which contains numeric numbers in any positions. For example, I want to make a string: secretcode, where secretcode.charAt(0)==(-21),...
2
by: Peter Afonin | last post by:
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: ...
4
by: Darrel | last post by:
How does HTML.encode work? I'm trying to save text in a hidden form field into a SQL DB. The tedt is HTML (from a WYSIWYG editor...X-standard). One problem I have is that stray apostrophe's in...
6
by: 7stud | last post by:
s1 = "hello" s2 = s1.encode("utf-8") s1 = "an accented 'e': \xc3\xa9" s2 = s1.encode("utf-8") The last line produces the error: --- Traceback (most recent call last):
4
by: J Peyret | last post by:
Well, as usual I am confused by unicode encoding errors. I have a string with problematic characters in it which I'd like to put into a postgresql table. That results in a postgresql error so I...
1
by: anonymous | last post by:
1 Objective to write little programs to help me learn German. See code after numbered comments. //Thanks in advance for any direction or suggestions. tk 2 Want keyboard answer input, for...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.