How to encode cookies

Discussion in 'ASP .Net' started by Peter Afonin, Apr 14, 2004.

  1. Peter Afonin

    Peter Afonin Guest

    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
    Peter Afonin, Apr 14, 2004
    #1
    1. Advertising

  2. 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
    "Peter Afonin" <> wrote in message
    news:...
    > 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
    >
    >
    Martin Dechev, Apr 14, 2004
    #2
    1. Advertising

  3. Peter Afonin

    Peter Afonin Guest

    Thank you very much, Martin. It worked.

    Peter

    "Martin Dechev" <> wrote in message
    news:...
    > 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
    > "Peter Afonin" <> wrote in message
    > news:...
    > > 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
    > >
    > >

    >
    >
    Peter Afonin, Apr 14, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,454
    Hans Kesting
    Feb 3, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    6,504
    Fredrik Lindner
    Nov 6, 2003
  3. user
    Replies:
    3
    Views:
    647
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Mar 31, 2007
  4. archana
    Replies:
    1
    Views:
    499
  5. _Who
    Replies:
    7
    Views:
    2,630
Loading...

Share This Page