asp.net Cookie的用法实例

作者:互联网   出处:控件中国网   2014-11-05 19:05:10   阅读:1

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);
            }
 

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat