Django SESSION_COOKIE_DOMAIN

发布于 2024-08-04 02:37:48 字数 344 浏览 3 评论 0原文

我在 django 中的 SESSION_COOKIE_DOMAIN 设置中看到一些神秘的东西。

通常,当我将其设置为“.mydomain.net”时,它可以正常工作。但有时 cookie 似乎没有被设置,因为当我登录时,会话中不会记住我,当我进入下一页时,我会变成 AnonymousUser。

在这些情况下,如果我更改设置文件以使 SESSION_COOKIE_DOMAIN 现在为 None 或“”,则站点行为将恢复正常。如果我将 SESSION_COOKIE_DOMAIN 更改回 mydomain,问题就会再次出现。

有什么想法吗?这可能是设置中的静默故障吗?或者这可能与我的服务器配置有关?或者我访问该网站的机器?

I'm seeing something mysterious with the SESSION_COOKIE_DOMAIN setting in django.

Normally, when I have this set to ".mydomain.net" it works fine. But occasionally cookies don't seem to be being set, because when I log in, I'm not remembered in the session and I become AnonymousUser when I get to the next page.

In these circumstances, if, I change my settings file so that SESSION_COOKIE_DOMAIN is now None or "", then the site behaviour returns to normal. If I change SESSION_COOKIE_DOMAIN back to mydomain, the problem returns.

Any ideas? Is this likely to be a silent failure in the settings? Or could it be something to do with my server configuration? Or the machine I'm accessing the site from?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

妳是的陽光 2024-08-11 02:37:48

您很可能最终会发送多个 sessionid cookie。如果您有一个域为“example.com”的 sessionid cookie 和另一个域为“.example.com”的 cookie,Django 将仅测试这些 sessionid 值之一。我不确定 Django 如何决定测试哪个 sessionid 值的有效性。

In all likelihood, you are ending up with multiple sessionid cookies being sent. If you have a sessionid cookie with domain 'example.com' and another cookie with domain '.example.com', Django will test only one of those sessionid values. I am unsure of how Django decides which sessionid value to test for validity.

泪是无色的血 2024-08-11 02:37:48

检查浏览器中的 cookie(在 FF 中,工具 -> 选项 -> 隐私 -> 有关 cookie 的内容),看看它们是否设置正确。搜索您的域,并查看是否设置了 sessionid cookie。

Check your cookies in your browser (in FF, Tools -> Options -> Privacy -> Something about cookies) and see if they are correctly set. Search for your domain, and see if you have the sessionid cookie is set.

白馒头 2024-08-11 02:37:48

正如保罗所说,这可能是浏览器问题。然而,我很想使用 Firebug 或 Firefox 中的实时 HTTP 标头进行一些 HTTP 分析。它是否试图正确设置 cookie?

It might be a browser issue as Paul suggests. However, I'd be tempted to do some HTTP analysis with Firebug or Live HTTP Headers in Firefox. Is it trying to set the cookie correctly?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文