cookIEs的創建:
在客戶端創建一個username的cookIEs,其值為gjy,有效期為1天.
方法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);
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));
Response.Write(Server.HtmlEncode(Request.CookIEs["user"]["passWord"].Value));
}