設定cookie可以直接使用 HttpCookie cookie = new cookie = new HttpCookie(COOKIE_NAME_FOR_USER); cookie.Expires = DateTime.Now.AddYears(1); cookie[COOKIE_USER_NAME] = "使用者名稱"; System.Web.HttpContext.Current.Response.Cookies.Add(cookie); 取: HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies.Get(COOKIE_NAME_FOR_USER); 刪除: System.Web.HttpContext.Current.Request.Cookies.Remove(COOKIE_NAME_FOR_USER); 另外,判斷是否有cookie可以直接使用取的cookie和null進行比較,如果取出來非null就說明不為空
設定cookie可以直接使用 HttpCookie cookie = new cookie = new HttpCookie(COOKIE_NAME_FOR_USER); cookie.Expires = DateTime.Now.AddYears(1); cookie[COOKIE_USER_NAME] = "使用者名稱"; System.Web.HttpContext.Current.Response.Cookies.Add(cookie); 取: HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies.Get(COOKIE_NAME_FOR_USER); 刪除: System.Web.HttpContext.Current.Request.Cookies.Remove(COOKIE_NAME_FOR_USER); 另外,判斷是否有cookie可以直接使用取的cookie和null進行比較,如果取出來非null就說明不為空