asp.net Cookie的用法实例
if (page.Request.Cookies[domain] == null)
{
HttpCookie cookies = new HttpCookie(domain);//定义cookie对象
cookies.Values[keys] = values;
DateTime dts = DateTime.Now;//定义时间对象
TimeSpan ts = new TimeSpan(0, 0, 20, 0);//cookie有效作用时间
cookies.Expires = dts.Add(ts);//添加作用时间
//cookies.Domain = ".hnzbtb.com"; 下级域名通用
page.Response.Cookies.Add(cookies);
}
else
{
HttpCookie cookies = page.Request.Cookies[domain];
cookies.Values[keys] = values;
DateTime dts = DateTime.Now;//定义时间对象
TimeSpan ts = new TimeSpan(0, 0, 20, 0);//cookie有效作用时间,具体查msdn
cookies.Expires = dts.Add(ts);//添加作用时间
//cookies.Domain = ".hnzbtb.com";
page.Response.Cookies.Add(cookies);
}