asp.Netでのcookiesの使用

903 ワード

C# :

  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));
}