今天在做项目的时候遇到了读取cookie的值出现乱码的情况
解决方法如下:
设置cookie 的值:
HttpCookie cookie = new HttpCookie("cookiename", System.Web.HttpContext.Current.Server.UrlEncode("anyben"));
Response.Cookies.Add(cookie);
Response.Cookies["cookiename"].Expires = DateTime.Now.AddHours(3);
读取cookie的值:
string cookiename = System.Web.HttpContext.Current.Server.UrlDecode(Request.Cookies["cookiename"].Value);
时间: 2024-12-28 07:09:32