Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Character Encoding Problem ASP.NET [modified]

Character Encoding Problem ASP.NET [modified]

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-netcomtutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cape Town Developer
    wrote on last edited by
    #1

    Hi all im stuck and really cant solve this one here goes... In asp ive got the following asp page that dumps a cookie with following name example "cronjé" when i read the name it reads fine after adding the nessary encoding type see below.

    Dim Name, Result
    Name = "cronjé"

    Response.charset="utf-8" ' // important dont omit this.
    Response.Cookies("TestCookie").Expires = Now + 60
    Response.Cookies("TestCookie")("test") = "1"
    Response.Cookies("TestCookie")("shopperName") = Name
    Response.Cookies("TestCookie").Domain = "www.cookiemonster.com"
    Result = Request.Cookies("TestCookie")("shopperName")
    Response.Write(Result)

    Output : "cronjé" this works fine as it dumps the cookie and reads it correctly no problem here. Using ie cookie viewer the value looks like this "shopperName=cronjé" My problem: Im maintaing a asp.net website that uses this cookie, when it reads it it does not display the name correctly.

     private void ReadASPCookie()
        {
            HttpCookie c = Request.Cookies\["TestCookie"\];
            if (c != null)
                lblName.Text = c.Values\["shopperName"\];
        }
    

    the output displays the name as "cronj%C3%A9" i dont understand why its doing this :( i even tried doing the following with no result. in the web.config i added the following encoding. still nothing :(

    <globalization 
       fileEncoding="utf-16"
       requestEncoding="utf-16"
       responseEncoding="utf-16"
      />
    

    i even tried setting the Response.Charset = "utf-8"; still nothing :( Can someone plz help me ?

    Wisdom is often meant as the ability and desire to make choices that can gain approval in a long-term examination by many people.

    modified on Tuesday, July 22, 2008 4:43 AM

    C N 2 Replies Last reply
    0
    • C Cape Town Developer

      Hi all im stuck and really cant solve this one here goes... In asp ive got the following asp page that dumps a cookie with following name example "cronjé" when i read the name it reads fine after adding the nessary encoding type see below.

      Dim Name, Result
      Name = "cronjé"

      Response.charset="utf-8" ' // important dont omit this.
      Response.Cookies("TestCookie").Expires = Now + 60
      Response.Cookies("TestCookie")("test") = "1"
      Response.Cookies("TestCookie")("shopperName") = Name
      Response.Cookies("TestCookie").Domain = "www.cookiemonster.com"
      Result = Request.Cookies("TestCookie")("shopperName")
      Response.Write(Result)

      Output : "cronjé" this works fine as it dumps the cookie and reads it correctly no problem here. Using ie cookie viewer the value looks like this "shopperName=cronjé" My problem: Im maintaing a asp.net website that uses this cookie, when it reads it it does not display the name correctly.

       private void ReadASPCookie()
          {
              HttpCookie c = Request.Cookies\["TestCookie"\];
              if (c != null)
                  lblName.Text = c.Values\["shopperName"\];
          }
      

      the output displays the name as "cronj%C3%A9" i dont understand why its doing this :( i even tried doing the following with no result. in the web.config i added the following encoding. still nothing :(

      <globalization 
         fileEncoding="utf-16"
         requestEncoding="utf-16"
         responseEncoding="utf-16"
        />
      

      i even tried setting the Response.Charset = "utf-8"; still nothing :( Can someone plz help me ?

      Wisdom is often meant as the ability and desire to make choices that can gain approval in a long-term examination by many people.

      modified on Tuesday, July 22, 2008 4:43 AM

      N Offline
      N Offline
      NeverHeardOfMe
      wrote on last edited by
      #2

      No promises, but instead of your: Response.charset="utf-8" try something along the lines of: Dim enc As System.Text.Encoding = System.Text.Encoding.Default Response.ContentEncoding = enc You may want to try different encoding values, but I've found, certainly as far as writing text files is concerned, that explicitly setting it to "Default" solves these sorts of problems.

      1 Reply Last reply
      0
      • C Cape Town Developer

        Hi all im stuck and really cant solve this one here goes... In asp ive got the following asp page that dumps a cookie with following name example "cronjé" when i read the name it reads fine after adding the nessary encoding type see below.

        Dim Name, Result
        Name = "cronjé"

        Response.charset="utf-8" ' // important dont omit this.
        Response.Cookies("TestCookie").Expires = Now + 60
        Response.Cookies("TestCookie")("test") = "1"
        Response.Cookies("TestCookie")("shopperName") = Name
        Response.Cookies("TestCookie").Domain = "www.cookiemonster.com"
        Result = Request.Cookies("TestCookie")("shopperName")
        Response.Write(Result)

        Output : "cronjé" this works fine as it dumps the cookie and reads it correctly no problem here. Using ie cookie viewer the value looks like this "shopperName=cronjé" My problem: Im maintaing a asp.net website that uses this cookie, when it reads it it does not display the name correctly.

         private void ReadASPCookie()
            {
                HttpCookie c = Request.Cookies\["TestCookie"\];
                if (c != null)
                    lblName.Text = c.Values\["shopperName"\];
            }
        

        the output displays the name as "cronj%C3%A9" i dont understand why its doing this :( i even tried doing the following with no result. in the web.config i added the following encoding. still nothing :(

        <globalization 
           fileEncoding="utf-16"
           requestEncoding="utf-16"
           responseEncoding="utf-16"
          />
        

        i even tried setting the Response.Charset = "utf-8"; still nothing :( Can someone plz help me ?

        Wisdom is often meant as the ability and desire to make choices that can gain approval in a long-term examination by many people.

        modified on Tuesday, July 22, 2008 4:43 AM

        C Offline
        C Offline
        Cape Town Developer
        wrote on last edited by
        #3

        Problem solved :)

        private void ReadASPCookie()
        {
        HttpCookie c = Request.Cookies["TestCookie"];
        if (c != null)
        lblName.Text = HttpUtility.UrlDecode(c.Values["shopperName"]);
        }

        Im not sure if HttpUtility.UrlDecode works for all special characters, but for now it solves my problem. :)

        Wisdom is often meant as the ability and desire to make choices that can gain approval in a long-term examination by many people.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups