Cookie乱码解决方法

后台:

  存值 (使用 HttpUtility.UrlEncode 进行编码)

Response.Cookies("ABC").Value = HttpUtility.UrlEncode("ABC")

  取值 (使用 HttpUtility.UrlDecode 进行解码)

Str = HttpUtility.UrlDecode(Request.Cookies("ABC").Value)

和JS进行交互:

在用js生成的cookie生用asp.net后台来读取的时候发现中文乱码

解决方法

System.Text.Encoding enc = System.Text.Encoding.GetEncoding("gb2312");
string cookie = Request.Cookies["outputData"].Value;
string cookievalue= HttpUtility.UrlDecode(cookie, enc);

posted @ 2011-07-07 14:00  hen  阅读(475)  评论(0编辑  收藏  举报