I have a code in my base page that retrieves a user name (IDname
) from an SQL database then saves the name in a cookie as follows:
HttpCookie ckIDname = new HttpCookie("ckIDname");
ckIDname.Value = IDname;
Response.Cookies.Add(ckIDname);
The cookie is retrieved as follows:
public static HttpCookie ckIDname { get { return HttpContext.Current.Request.Cookies["ckIDname"]; } }
public static string ckIDnameValue { get { if (ckIDname != null) return ckIDname.Value as string; else return string.Empty; } }
So far so good. However if the cookie contains Swedish letters (åäö) I only get encoded characters (i.e. if IDname
is Göran I get it from the cookie as G%C3%83%C2%B6ran).
I tried many attempts (HttpUtility.HtmlEncode
, HttpUtility.HtmlDecode
, HttpUtility.UrlDecode
) to get the letters to their original state but without luck. The name in the SQL database is correct (Göran). Moreover I don't have any problem writing Swedish letters in HTML tags. They are all correct. My only problem is to get Swedish letters from cookies correctly. Any help would be highly appreciated!