使用cookie保存用户登录信息
写入Cookie
HttpCookie _cookie = new HttpCookie("User"); _cookie.Values.Add("UserName", login.UserName); _cookie.Values.Add("Password", login.Password); Response.Cookies.Add(_cookie);
读取Cookie
HttpCookie _cookie = httpContext.Request.Cookies["User"]; string _userName = _cookie["UserName"]; string _password = _cookie["Password"]; httpContext.Response.Write("用户名:"+_userName);
退出Cookie
HttpCookie _cookie = Request.Cookies["User"]; _cookie.Expires = DateTime.Now.AddHours(-1); Response.Cookies.Add(_cookie);