一.Cookie
public static void GetDB(string ID, string Name) { HttpCookie DBName = new HttpCookie("DB", ID); HttpCookie DB = new HttpCookie("DBName", Name); //设置过期时间 DateTime dt = DateTime.Now; TimeSpan ts = new TimeSpan(0, 24, 0, 0, 0);//过期时间为10分钟 DBName.Expires = dt.Add(ts); DB.Expires = dt.Add(ts); //ToKen.setMaxAge(60 * 10); //Cookie保存时间 HttpContext.Current.Response.AppendCookie(DBName); HttpContext.Current.Response.AppendCookie(DB); HttpContext.Current.Request.Cookies["DB"].Value = ID; HttpContext.Current.Request.Cookies["DBName"].Value = Name; }
三.关于过期时间TimeSpan
TimeSpan ts0 = new TimeSpan(30); //将时间间隔ts0初始化为30刻度数 TimeSpan ts1 = new TimeSpan(1, 30, 30); //将时间间隔ts1初始化为1小时30分30秒 TimeSpan ts2 = new TimeSpan(2,12,30,30); //将时间间隔ts2初始化为2天12小时30分30秒 TimeSpan ts3 = new TimeSpan(7, 12, 30, 30,30); //将时间间隔ts3初始化为7天12小时30分30秒30毫秒