1.判断所需cookie是否存在,新建1个cookie判断其是否指向null
2.删除cookie的方法为设置保存时间为-1,并将其加入Respond.Cookies列表中
protected void Page_Load(object sender, EventArgs e) { HttpCookie cookie=Request.Cookies["name"];//获取客户端Cookie if (cookie == null)//如果不存在该名称的Cookie { cookie = new HttpCookie("name", "zhoufoxcn"); cookie.Expires = DateTime.Now.AddDays(10);//设置cookie保存10天 Response.Cookies.Add(cookie);//将cookie发送到客户端保存 } else { Response.Write("cookie中保存的数据是:" + cookie.Value); cookie.Expires = DateTime.Now.AddYears(-1); Response.Cookies.Add(cookie);//将cookie发送到客户端,这样就能删除掉cookie } }