簡體   English   中英

Cookies和瀏覽器

[英]Cookies and browsers

Request.Cookies讀取cookie時,如果我使用的是firefox,則應為cookie名稱seekpunk一個特殊字符,例如,如果cookie名稱是seekpunk則代碼應如下所示: Request.Cookies["~seekpunk"]為什么要做firefox需要一個特殊字符來確定我的cookie名稱,這與不同的瀏覽器不同嗎?

我認為您不需要在名稱前使用特殊字符,通常我在閱讀時僅使用(indexOf(seekpunk)!=-1)檢查cookie。 安裝用於firefox的firecookie,並檢查cookie名稱是否為“〜seekpunk”(如果是),您的代碼必須在某個地方生成該名稱。

https://developer.mozilla.org/en/DOM/document.cookie https://developer.mozilla.org/en/Code_snippets/Cookies

javascript

函數read(){

            var Cookie_Name = "MyTestCookie";

            var sessionValue = null;

            if (document.cookie) {

                var currentDocumentCookie = document.cookie.split(';');
                alert(document.cookie);
                var lengthCookie = currentDocumentCookie.length;


                for (j = 0; j < lengthCookie; j++) {

                    var singleCookie = currentDocumentCookie[j];

                    alert(singleCookie);

                    while (singleCookie.charAt(0) == ' ') {
                        singleCookie = singleCookie.substring(1, singleCookie.length);
                    }

                }

               return 1;

            }
            else {
                return 0;
            }
        }

讀();

C#HttpCookie myCookie =新的HttpCookie(“ MyTestCookie”); DateTime現在= DateTime.Now;

        // Set the cookie value.
        myCookie.Value = now.ToString();
        // Set the cookie expiration date.
        myCookie.Expires = now.AddMinutes(1);

        // Add the cookie.
        Response.Cookies.Add(myCookie);

        Response.Write("<p> The cookie has been written.");

因此它一定是您的代碼,我在工作中太忙了,抱歉無法及時回復。 小測試,測試自己。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM