同桌上课用手指进去了好爽_欧美丰满熟妇xxⅹⅹ性大i_成人av天天日天天拍拍_猛男gay帅男gay男男同志_欧美va天堂在线观看_人妻无码av中文系列三里桃花_亚欧免费无码在线观看_久久久精品国产亚洲av水_日韩在线免费看污污污_2021无码专区人妻系列日韩

首頁(yè) 優(yōu)化推廣 ASP.NET中Cookies的用法

ASP.NET中Cookies的用法

來(lái)源: | 時(shí)間:2013/4/23 22:01:13 |

一, cookies 寫(xiě)入

方法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);

 

創(chuàng)建帶有子鍵的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);//這里設(shè)置要保存多長(zhǎng)時(shí)間.
Response.Cookies.Add(UserCookie);

 

二,cookies的讀取: 

無(wú)子鍵讀取: 
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);

}

服務(wù)熱線

153 8323 9821

功能和特性

價(jià)格和優(yōu)惠

網(wǎng)站和維護(hù)

推廣和優(yōu)化

微信服務(wù)號(hào)