Cookie和浏览器

时间:2012-02-16 10:57:09

标签: c# javascript

Request.Cookies中读取cookie时如果我使用的是firefox,我应该为cookie名称添加一个特殊字符,例如,如果cookie名称为seekpunk,则代码应如下所示:{{ 1}}为什么firefox需要一个特殊的字符来确定我的cookie名称,这与不同的浏览器不同?

2 个答案:

答案 0 :(得分:0)

我认为你不需要在名字前面加上特殊字符,通常我只是在阅读时检查cookie时使用(indexOf(seekpunk)!= - 1)。 为firefox安装firecookie并检查cookie名称是否为“〜seekpunk”,如果是,您的代码必须在某处生成此名称。

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

答案 1 :(得分:0)

的javascript

function 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 now = 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.");

所以一定是你的代码,我工作太忙,抱歉迟到了。小测试,测试你自己。