日期:2014-05-17 浏览次数:20660 次
//写入cookie方法SetUser2(string Name,string Pwd)
DateTime expires = default(DateTime);
expires=DateTime.Now.AddHours(1);//1小时
HttpCookie cookie = new HttpCookie(CookieName);
cookie.Values.Add("n", Name);
cookie.Values.Add("P", Pwd);//密码
cookie.Values.Add("T", expires.ToString("yyyy-MM-dd HH:mm:ss"));//时间
HttpContext.Current.Response.Cookies.Set(cookie);
//读取cookie方法
HttpCookie cookie = HttpContext.Current.Request.Cookies[CookieName];
if (cookie != null)
{
string Name = cookie.Values["n"];
string PWD = cookie.Values["P"];
//如何取出时间 并判断是否过期?
//如果没过期则从新写入1小时过期时间,如果过期则同样创建新cookie
//从新写入cookie
SetUser2(this._Name, this.Pwd);
return true;
}