C#中Cookie的寫入與讀取


HttpCookie cookie = new HttpCookie("guid");   //創建

cookie.Values["id"] = “123456789”; //將“123456789”寫入id

HttpContext.Current.Response.AppendCookie(cookie); //保存

 

HttpCookie cookie  = HttpContext.Current.Request.Cookies[“guid”]; //讀取

string id = cookie.Values["id"].ToString(); //id="123456789"

 

cookie.Expires 可以設置過期時間,一般不進行設置默認關閉瀏覽器后失效


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM