Cookies的用法——用戶登陸和註銷

關於cookies的詳細用法——用戶登陸和註銷(.NET版) 登陸(記錄Cookies用戶名)
HttpCookie myCookie = new HttpCookie("userinfo");
myCookie["uname"] = txtName.Text.Trim();
myCookie.Expires = DateTime.Now.AddDays(1d);
Response.Cookies.Add(myCookie);cookie

顯示(用戶名)ide

if (Request.Cookies["userinfo"] != null)
{it

   if (Request.Cookies["userinfo"]["uname"] != null)
  { userName.Text = Convert.ToString(Request.Cookies["userinfo"]["uname"]); }
}cookies

刪除Cookiesclass

if (Request.Cookies["userinfo"] != null)
{
HttpCookie myCookie = new HttpCookie("userinfo");
myCookie["uname"] = null;
myCookie.Expires = DateTime.Now.AddDays(-1d);
Response.Cookies.Add(myCookie);登錄

   }im

相關文章
相關標籤/搜索