All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
ASP.NET中Cookie的使用介绍_[Asp.Net教程]

Writer: 归海一刀 Article type: Programming skills(编程技巧) Time: 2014/1/30 1:18:14 Browse times: 240 Comment times: 0

ASP.NET中Cookie的使用介绍_[Asp.Net教程]


Head photo

Go homepage
Upload pictures
Write articles

ASP.NET中Cookie的使用介绍_[Asp.Net教程] Cookie为客户端信息存放对象,可以把用户的信息保存在用户本地,不必总是访问服务器

与Session不同,Session为用户全局变量,对于该用户的所有操作过程都有效。

//创建Cookie对象

HttpCookie newCookie = new HttpCookie("User");

//Cookie中添加信息项:为键值对,key/value

newCookie.Values.Add("Name",tbUserName.Text.Trim());
newCookie.Values.Add("Psd",tbUserPsd.Text.Trim());

//如果不设置Expires属性,即为临时Cookie,浏览器关闭即消失

newCookie.Expires = DateTime.Now.AddDays(1); //设置过期天数为1天

//通过Request对象读取得到Cookies的值

HttpCookie newCookie = Request.Cookies["User"];

//通过Response对象写入客户端的Cookie

newCookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(newCookie);




There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.