一、写入:
HttpCookie cook = new HttpCookie("abcname"); cook.Expires = DateTime.Now.AddYears(1);//设定过期时间 cook["username"] = user.Uname; Response.Cookies.Add(cook);
二、读取:
HttpCookie cook = Request.Cookies["abcname"]; string name = string.Empty; if (cook != null) { name = Convert.ToString(cook["username"]); }