HttpCookie cookie = new HttpCookie("Cloud");
DateTime dt = DateTime.Now;
TimeSpan ts = new TimeSpan(1, 0, 0);
cookie.Expires = dt.Add(ts);
cookie.Values.Add("Count", login_count.ToString());
Response.AppendCookie(cookie);
一行脚本:
cookie.Expires=DateTime.Now.AddHour(1)
cookie.Expires=DateTime.Now.Add(new TimeSpan(1, 0, 0));
赋值:
方法一:Response.Cookies["Cloud"]["Count"]= (Convert.ToInt16(cookie["Count"]) + 1).ToString();
方法二:cookie.Values["Count"] = (Convert.ToInt16(cookie["Count"]) + 1).ToString();
取值:
方法一:
Request.Cookies["Cloud"]["Count"]
cookie.["Count"]
据说 expire是刷新后无法取值,原因是:
expire=你设定的时间-当前时间,是一个不定的值,所以无法取值
expire=初始值,可单独设置cookie存
|