- PHP 变量作用域
- 10690网关短信群发平台申请办理
- 经典SQL语句大全之应用篇
- 时间戳
- 网站分析及竞争对手的分析
- 移动控件介绍及详细使用方法:ObjectList 控件
- 网站不带www为什么要比带www的收录要多一些
- ASP.NET中常用的26个优化性能方法
- 教你如何分析对手 网站用户忠诚度
- .net中Web.config文件的基本原理及相关设置
邮箱:
手机:15383239821
ASP.NET中Cookies的用法
一, cookies 写入
方法1:
Response.Cookies["username"].Value="gjy";
Response.Cookies["username"].Expires=DateTime.Now.AddDays(1);
方法2:
System.Web.HttpCookie newcookie=new HttpCookie("username");
newcookie.Value="gjy";
newcookie.Expires=DateTime.Now.AddDays(1);
Response.AppendCookie(newcookie);
创建带有子键的cookies:
System.Web.HttpCookie newcookie=new HttpCookie("user");
newcookie.Values["username"]="gjy";
newcookie.Values["password"]="111";
newcookie.Expires=DateTime.Now.AddDays(1);
Response.AppendCookie(newcookie);
或者
HttpCookie UserCookie = new HttpCookie("KindCode");
UserCookie["bigKind"] = lstBigKindCode.SelectedValue.Trim();
UserCookie["smallKind"] = lstSmallKindCode.SelectedValue.Trim();
UserCookie["UserName"] = strUserName;
UserCookie["userKind"] = lsbUserSmallKindCode.SelectedValue;
UserCookie.Expires = DateTime.Now.AddDays(1);//这里设置要保存多长时间.
Response.Cookies.Add(UserCookie);
二,cookies的读取:
无子键读取:
if(Request.Cookies["username"]!=null)
{
Response.Write(Server.HtmlEncode(Request.Cookies["username"].Value));
}
有子键读取:
if(Request.Cookies["user"]!=null)
{
Response.Write(Server.HtmlEncode(Request.Cookies["user"]["username"].Value));
}
或者
HttpCookie cookie = Request.Cookies["KindCode"];
if (cookie != null)
{
string bigKind = cookie.Values["bigKind"];
string userName = cookie.Values["UserName"];
}
三,cookies的清除
HttpCookie cookie = Request.Cookies["KindCode"];
if (cookie != null)
{
cookie.Expires = DateTime.Now.AddDays(-2);
Response.Cookies.Set(cookie);
}
- 上一篇:C#读取设置Cookie
- 下一篇:Cookie应用小总结
-
2012-10-11Server Application Unavailable 错误解决办法
-
2010-07-20怎样确定网站优化的关键字
-
2019-11-15C#使用JavaScriptSerializer类实现序列化与反序列化得到JSON
-
2011-04-18C#泛型List
-
2012-06-30浅析单向链接对网站优化的影响
-
2023-09-21PHP 中超级全局变量
