//1.编写(创建 和 修改 一样)
HttpCookie cookie = new HttpCookie("userName");
cookie.Value = "顾志海";
cookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie);
//2.读取
if (Request.Cookies["userName"] != null)
{
string userName = Request.Cookies["userName"].Value;
userName = Server.HtmlEncode(userName);//确保恶意用户没有向 Cookie 中添加可执行脚本
}
//3.删除
HttpCookie cookie = new HttpCookie("userName");
cookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(cookie);