写cookie
HttpCookie UserCookie = new HttpCookie("userName");
UserCookie["name"]=dr["user"].ToString();
UserCookie.Expires=DateTime.Now.AddDays(1);//这里设置要保存多长时间.
Response.Cookies.Add(UserCookie);
读取的时候
HttpCookie cookie=Request.Cookies["userName"];
string name=cookie.Values["name"];
清除cookie
HttpCookie cookie=Request.Cookies["userName"];
if(cookie!=null)
{
cookie.Expires=DateTime.Now.AddDays(-2);
Response.Cookies.Set(cookie);
}