ASP.NET中的cookie读写方法
2010-09-09 22:19
507 查看
Cookie (HttpCookie的实例)提供了一种在 Web 应用程序中存储用户特定信息的方法。例如,当用户访问您的站点时,您可以使用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.
本贴来自天极网群乐社区--http://q.yesky.com/group/review-18114556.html
当该用户再次访问您的网站时,应用程序便可以检索以前存储的信息。
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.
本贴来自天极网群乐社区--http://q.yesky.com/group/review-18114556.html
相关文章推荐
- ASP.NET中cookie读写方法
- ASP.NET中的cookie读写方法介绍
- ASP.NET中cookie读写方法介绍
- ASP.NET C#读写Cookie的方法!
- ASP.NET中cookie读写方法介绍
- ASP.NET中cookie读写方法介绍
- ASP.NET中cookie读写方法介绍本
- ASP.NET中的cookie读写方法介绍
- ASP.NET中的cookie读写方法
- ASP.NET中cookie读写方法
- [转]ASP.NET中的cookie读写方法
- ASP.NET中的cookie读写方法
- ASP.NET中cookie读写方法
- ASP.NET中cookie读写方法介绍
- ASP中Cookie读写的实现方法
- ASP.NET MVC WebApi 返回数据类型序列化控制(json,xml) 用javascript在客户端删除某一个cookie键值对 input点击链接另一个页面,各种操作。 C# 往线程里传参数的方法总结 TCP/IP 协议 用C#+Selenium+ChromeDriver 生成我的咕咚跑步路线地图 (转)值得学习百度开源70+项目
- asp.net读写cookie的类
- asp.net cookie的读写实例
- c#.net与vb.net中读写Cookie的方法!
- 关于asp.net中cookie在调试过程中读写正常发布后乱码问题