首页 > 其他 > 详细

Cookies的读取、写入、有效期设置

时间:2014-05-10 00:21:08      阅读:229      评论:0      收藏:0      [点我收藏+]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
protected void Page_Load(object sender, EventArgs e)
{
    //设置Cookies
    HttpCookie cookie = new HttpCookie("UserName","ZhangSan");
    this.Request.Cookies.Add(cookie);
 
    //设置Cookies有效期
    DateTime time = DateTime.Now;
    TimeSpan span = new TimeSpan(0, 0, 15, 0, 0);//时间间隔
    cookie.Expires = time.Add(span);//设置有效期为15分钟
 
    //读取Cookies
    string userName = this.Request.Cookies[0].Value;
    this.Response.Write(userName);
 
    //写入Cookies
    this.Response.SetCookie(cookie);
}

  

Cookies的读取、写入、有效期设置,布布扣,bubuko.com

Cookies的读取、写入、有效期设置

原文:http://www.cnblogs.com/heqilin/p/3718584.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!