asp.net 2.0中cookie中文值为乱码,求教大家如何解决!!!
我是按这样写入cookie的
HttpCookie MyCookie = new HttpCookie( "user_name ");
MyCookie.Value = username.Value;
Response.Cookies.Add(MyCookie);
可是读出 Request.Cookies[ "user_name1 "].Value的值是乱码,求大家帮帮忙!!
[解决办法]
try
HttpCookie MyCookie = new HttpCookie( "user_name ");
MyCookie.Value = Server.UrlEncode(username.Value);
Response.Cookies.Add(MyCookie);
Server.UrlDecode(Request.Cookies[ "user_name1 "].Value)
[解决办法]
//写的时候,编码为Server.UrlEncode
HttpCookie UserName=new HttpCookie( "UserName ",Server.UrlEncode(username));
UserName.Expires=DateTime.Now.AddDays(1);
Response.Cookies.Add(UserName);
//读取的时候,解码为Server.UrlDecode
Server.UrlDecode(Request.Cookies[ "UserName "].Value);
这样就可以了.
[解决办法]
编码 和 解码 即可
像上面孟子 老大说的
还有
web.config中
<globalization requestEncoding= "gb2312 " responseEncoding= "gb2312 "/>