Character Encoding Problem ASP.NET [modified]
-
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
-
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
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.
-
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
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.