不能通过302重定向阅读在Firefox / Chrome浏览器的cookies,但在IE工程 [英] Unable to read cookies in FireFox/Chrome via 302 redirect, but works in IE

查看:198
本文介绍了不能通过302重定向阅读在Firefox / Chrome浏览器的cookies,但在IE工程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打破我的脑袋想出一个浏览器的具体问题(在Firefox和Chrome)。我花了这么多时间来尝试解决这个问题,我终于想到创建这里的专家来研究这个问题进行现场演示。 (希望不负有心人)

I am breaking my head to figure out a browser specific issue (in Firefox and Chrome). I have spent so much time to try fixing this issue that I have finally thought to create a live demo for the experts here to look into this issue. (Hopefully it pays off)

我有两个域 www.nkmekal.com 并的 www.incessantcoding.com

请使用Firefox / Chrome浏览器复制问题:

Please use Firefox/Chrome to replicate the issue:

第1步:

http://www.nkmekal.com/createcookie.aspx

页面只是创建的cookie。下面是创建cookie中的code:

The page just creates a cookie. Below is the code that creates the cookie:

    // In On_Load of nkmekal.com/createCookie.aspx
    HttpCookie cookie = new HttpCookie("DisCookie");
    cookie.Value = "djdjd77676ydjdndgdidjkdnhf";
    cookie.HttpOnly = true;
    cookie.Expires = DateTime.Now.AddDays(1);
    Response.Cookies.Add(cookie);
    lblCookieInfo.Text = string.Format("<b>Cookie Name:</b> {0} <br/><br/> <b>Cookie Value:</b> {1} <br/><br/> <b>Cookie Expires On:</b> {2}", cookie.Name, cookie.Value, cookie.Expires);

第二步:

现在在浏览器中打开一个新标签,转到 http://www.incessantcoding.com/GoTonkmekal的.aspx 基本上没有一个简单的302重定向到 http://www.nkmekal.com/ReadCookie的.aspx ,下面是code,这是否重定向:

Now open a new tab in the browser, go to http://www.incessantcoding.com/GoTonkmekal.aspx which basically does a simple 302 redirect to http://www.nkmekal.com/ReadCookie.aspx , below is the code that does this redirect:

// In On_Load of incessantcoding.com/GoTonkmekal.aspx
protected void Page_Load(object sender, EventArgs e)
{
    Response.Redirect("http://www.nkmekal.com/ReadCookie.aspx");
}

不过,我看到下面的消息:(请参阅ReadCookie.aspx页的code在步骤3)

However I see the below message: (Please see the code of ReadCookie.aspx page in Step 3)

没有cookie中:(

这意味着该域的 www.nkmekal.com 无法读取其先前创建的,当你浏览的 www.nkmekal.com/createcookie.aspx

Which means that the domain www.nkmekal.com was unable to read the cookie that it created earlier when you’ve browsed www.nkmekal.com/createcookie.aspx

第3步:

和页面 http://www.nkmekal.com/ReadCookie.aspx 只是试图阅读上面创建的cookie(在步骤1中),并显示cookie数据。下面是试图读取cookie并将其显示在页面中的code

And the page http://www.nkmekal.com/ReadCookie.aspx just tries to read the above created cookie (in Step 1) and displays cookie data. Below is the code that tries to read the cookie and displays it in the page

    // In On_Load of nkmekal/ReadCookie.aspx
    HttpCookie cookie = Request.Cookies["DisCookie"];
    if (cookie != null)
    {
      // Resetting expiry date because the browser never sends expiry date to Server,
      // as cookies expiration dates are irrelevant to servers.
      cookie.Expires = DateTime.Now.AddDays(1);
      lblCookieInfo.Text = string.Format("<b>Yes! I found a cookie</b> <br><br><b>Cookie Name:</b> {0} <br/><br/> <b>Cookie Value:</b> {1} <br/><br/> <b>Cookie Expires On:</b> {2}", cookie.Name, cookie.Value, cookie.Expires);
    }
    else
    {
        lblCookieInfo.Text = "No Cookie Found :(";
    }

以上步骤做工精细只能在IE浏览器,但不能在Firefox / Chrome浏览器。

The above steps work fine only in IE but not in FireFox/Chrome.

另外,如果你想采取偷看在两个域的来源$ C ​​$ C你可以在

Also, if you want to take a peek at the source code of the two domains you can download them at

http://dl.dropbox.com/u/1248159/incessantcoding.zip

http://dl.dropbox.com/u/1248159/nkmekal.zip

为什么我试图做到这一点:

那么,为什么我试图做到这一点的原因是,有一些我需要在域 www.incessantcoding.com 执行,如果有某些操作中创建的cookie的 www.nkmekal.com

So, the reason why I am trying to do this is that there are certain operations that I need to perform in the domain www.incessantcoding.com if there was a cookie created in www.nkmekal.com

和与302重定向的去的原因是我们无法读取跨域的Cookie,所以我想从适当的域读饼干只(因为nkmekal.com只能读取它的cookie)。

And the reason for going with a 302 redirect is that we cannot read cross domain cookies and hence I am trying to get the cookies read from the appropriate domain only (since nkmekal.com can only read its cookies).

任何帮助/建议将是非常有益的。

Any help/suggestions will be very helpful.

更新:
也挺有趣的,如果步骤1和3位进行(省去步骤2),cookie的值被读入Firefox和Chrome正确。它只有302方式是行不通的。

Update: Also quite interestingly, if steps 1 and 3 are performed (leaving out step 2), the cookie value is read in Firefox and Chrome correctly. Its only the 302 way that isn't working.

推荐答案

我终于想通了,替代它工作就好了!
这里就是我所做的:

I have finally figured out an alternative and it works just fine! Here is what I've did:

如果 nkmekal.com 创建 DisCookie ...我issueing 302重定向为 incesscantcoding.com 与加密令牌作为查询字符串值,然后点击 incessentcoding.com 会创建自己的 DisCookie 基于其领域查询字符串值,所以如果我想知道是否存在的 nkmekal一个cookie .COM 我只看了Cookies集合了 DisCookie incessantcoding.com ...我测试这种情况下,它似乎在这两个是工作Firefox和Chrome ...

If nkmekal.com creates a DisCookie...I am issueing a 302 redirect to incesscantcoding.com with an encrypted token as a querystring value, then incessentcoding.com will create its own DisCookie based on the querystring value for its domain, so if I want to know if a cookie exists for nkmekal.com I will just look at the Cookies collection for a DisCookie in incessantcoding.com ... I tested this scenario and it seems to be working in both firefox and chrome...

和后来我想通,即使谷歌没有类似的事情,当用户登录到他们的服务的网站之一...

AND later I figured that even google does similar thing when a user logs into one of their service websites...

希望这有助于...

这篇关于不能通过302重定向阅读在Firefox / Chrome浏览器的cookies,但在IE工程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆