標籤:
Cookie路徑Google瀏覽器依次點擊設定--進階選項--內容設定--cookies--選擇“顯示cookies和其他網站資料”按鈕就可以看到了
C:\Users\Administrator\Local Settings\Application Data\Google\Chrome\User Data\Default
IE瀏覽器
C:\Users\Administrator\AppData\Local\Microsoft\Windows\Temporary Internet Files 注意:只有設定有失效期的 cookie 在離開設定頁時會以檔案形式儲存 C:\Users\Administrator\CookiesC:\Users\Administrator\AppData\Local\Microsoft\Windows\Temporary Internet FilesC:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Cookies 查看Cookie
下面看看代碼就什麼都知道了我的總結都在下面
protected void Page_Load(object sender, EventArgs e) { HttpCookie c1 = new HttpCookie("a", "123"); HttpCookie c2 = new HttpCookie("a", "456"); //注意覆蓋了同名的cookie c2.Values.Add("e", "hello");//看看這個會是什麼效果呢? 哈哈讀取之後【js讀取】 是 //a=456&e=hello;c=789; 會把hello一起寫在Cookie “a”裡面去 if (Request.Cookies["a"] != null) { //Response.Write(Request.Cookies["a"].Value);//456&e=hello //Response.Write(Request.Cookies["a"]["e"].ToString());//hello System.Collections.Specialized.NameValueCollection d = Request.Cookies["a"].Values; foreach (var item in d.AllKeys) { Response.Write(item + ":" + d[item] + "<br />"); //:456 //e:hello } } //設定一個到期時間 c2.Expires = DateTime.Now.AddMinutes(30); HttpCookie c3 = new HttpCookie("c", "789"); //如果要寫入中文的話 請先編碼好 string ch = Server.UrlEncode("中文="); HttpCookie c4 = new HttpCookie("d", ch); HttpCookie c5 = new HttpCookie("t", "="); Response.AppendCookie(c1); Response.AppendCookie(c2); Response.AppendCookie(c3); Response.AppendCookie(c4); Response.AppendCookie(c5); //總結:每執行個體化一個Cookie對象就會在瀏覽器中建立一個Cookie檔案 //如果沒有設定cookie到期時間,那麼Cookie就是瀏覽器會話Cookie,瀏覽器關閉 Cookie就會消失 //如果執行個體化的Cookie有相同名字的,則後面的會覆蓋前面的 //看上面的代碼就知道怎麼回事兒了 //Values Cookie集合Request.Cookies["a"]["e"].ToString() 通過這個方式追個訪問cookie的值 //Value 訪問寫入Cookie的所有值, //哈哈現在 疑惑消除了 }js讀取 <div> <input type="button" value="ok" onclick="fun()" /> </div> <script type="text/javascript"> function fun() { document.write(decodeURIComponent(document.cookie)); } </script>
ASP.NET-【狀態管理】-Cookie小結