简单的存储Cookie和获取Cookie例子
public string SaveCookie(string name)
{
// 登陆成功要将必要数据存储到 Cookie 里
HttpCookie httpCookie = new HttpCookie("cookie");
// 设置过期时间
httpCookie.Expires = DateTime.Now.AddHours(1);
// 设置姓名
httpCookie.Values.Add("name", name);
Response.SetCookie(httpCookie);
return name;
}
public string GetCookie()
{
string name = Request.Cookies["cookie"]["name"];
return name;
}