如何获取专门针对 Rails 中的子域的 cookie?
我遇到了为当前子域获取正确 cookie 的问题。我有同一应用程序的两个不同实例,一个在 www
子域运行,另一个在 test
子域运行,但测试应用程序似乎正在拉入 cookie相反,即使有 .test.domain.com
的显式 cookie(因为它是同一应用程序的不同实例,cookie 名称是相同的,但我我不想在两个实例之间共享会话或 cookie)。
有什么方法可以指定 Rails 应该在哪个域中查找其 cookie?我将 config.cookies.domain 和 config.action_controller.session[:domain] 均设置为“test.domain.com”(在测试应用程序),但似乎没有任何区别(而且,由于某种原因,测试域设置的 cookie 以域 .test.domain.com
而不是 test.domain.com
,我不确定为什么,或者是否相关)。
更新:为了让事情变得更复杂,我意识到我实际上需要以点开头的 cookie 域(即 .test.domain.com
和 .domain。 com
),因为一般来说,子域应该共享主域的 cookie 和会话(只是测试子域实际上是它自己的应用程序,而不是主应用程序的子域) )。显然 .domain.com
cookie 将适用于 test.domain.com
,但是有什么方法可以显式地设置 test.domain.com
那些优先?
I'm running into an issue with getting the right cookies for the current subdomain. I have two different instances of the same application, one running at the www
subdomain and the other running at the test
subdomain, but it seems like the test app is pulling in cookies from the www
instead, even if there are explicit cookies for .test.domain.com
(because it's different instances the same application, the cookie name is the same, but I am not looking to share sessions or cookies between the two instances).
Is there any way to specify what domain Rails should be looking for its cookies for? I have config.cookies.domain
and config.action_controller.session[:domain]
both set to "test.domain.com"
(on the test app), but it doesn't seem to make any difference (and, as well, the cookies being set by the test domain are for some reason ending up with the domain .test.domain.com
instead of test.domain.com
and I'm not sure why, or if it's relevant).
Update: To make this more complex, I realized I do actually need the dot-prefaced cookie domains (ie. .test.domain.com
and .domain.com
), because in general, subdomains are supposed to share the main domain's cookies and session (it's only that the test subdomain is actually it's own application rather than being a subdomain of the main application). Obviously .domain.com
cookies will apply to test.domain.com
, but is there any way to make the explicitly test.domain.com
ones take priority?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论