展会信息港展会大全

ASP.NET中读取写入cookie数据示例代码
来源:互联网   发布日期:2016-01-27 15:30:02   浏览:2542次  

导读:ASP NET中的cookie:创建Cookie方法 (1)Response Cookies[userName] Value = admin;Response Cookies[userName] Expires = DateTime Now AddDays(1); 如果不设置失效时间,Cookie信息不会写到用户硬盘,浏 ...

ASP.NET中的cookie:创建Cookie方法 (1)

Response.Cookies["userName"].Value =admin";

Response.Cookies[ userName ].Expires = DateTime.Now.AddDays(1);

//如果不设置失效时间,Cookie信息不会写到用户硬盘,浏览器关闭将会丢弃。

ASP.NET中的cookie:创建Cookie方法 (2)

HttpCookie aCookie = new HttpCookie( lastVisit );

//上一次访问时间

aCookie.Value = DateTime.Now.ToString();

aCookie.Expires = DateTime.Now.AddDays(1);

Response.Cookies.Add(aCookie);

ASP.NET中的cookie:访问Cookie方法(1)

if(Request.Cookies["userName"] != null)

Label1.Text = Server.HtmlEncode(Request.Cookies["userName"].Value);

访问Cookie方法(2)

if(Request.Cookies["userName"] != null) {

HttpCookie aCookie = Request.Cookies["userName"];

Label1.Text = Server.HtmlEncode(aCookie.Value);

}

ASP.NET中的cookie:创建多值Cookie方法 (1)

Response.Cookies["userInfo"]["userName"] =admin";

Response.Cookies["userInfo"]["lastVisit"] = DateTime.Now.ToString();

Response.Cookies["userInfo"].Expires = DateTime.Now.AddDays(1);

ASP.NET中的cookie:创建多值Cookie方法 (2)

HttpCookie aCookie = new HttpCookie("userInfo");

aCookie.Values["userName"] =admin";

aCookie.Values["lastVisit"] = DateTime.Now.ToString();

aCookie.Expires = DateTime.Now.AddDays(1);

Response.Cookies.Add(aCookie);

ASP.NET中的cookie:读取多值Cookie

HttpCookie aCookie = Request.Cookies["userInfo"];

string userName=aCookie.Values[ userName ];

string lastVisit=aCookie.Values[ lastVisit ];

ASP.NET中的cookie:修改和删除Cookie

不能直接修改或删除Cookie,只能创建一个新的Cookie,发送到客户端以实现修改或删除Cookie。

赞助本站

人工智能实验室

相关热词: cookie 读取 写入 ASP NET

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港