Rails:仅在 www 子域上设置 cookie?

发布于 2024-09-18 15:06:59 字数 268 浏览 3 评论 0原文

我已在 asset.domain.com 上设置了资产主机,但 cookie 似乎是随请求一起发送到 assets.domain.com 的。我在某处读到,如果您将cookie设置为domain.com,那么就会发生这种情况。

所以我想我只是尝试将 cookie 设置为 www.domain.com,以便对 assets.domain.com 的请求不会发送 cookie。 (我还有一个从domain.com到www.domain.com的永久重定向)

我如何在Rails中执行此操作?

I have set up an asset host at assets.domain.com but it appears that cookies are being sent with requests to assets.domain.com. I read somewhere that if you have cookies set to domain.com then this will happen.

So I guess I'm trying to set cookies only to www.domain.com so that requests to assets.domain.com will not send cookies. (I also have a permanent redirect from domain.com to www.domain.com)

How do I do this in Rails??

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

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

发布评论

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

评论(1

那伤。 2024-09-25 15:06:59

要在特定域上设置 cookie:

cookies[:my_cookie] = {:value => 'Tasty Cookie', :domain => 'www.domain.com'}

一个问题是,在删除特定于域的 cookie 时,您还必须指定域:

cookies.delete(:my_cookie, :domain => 'www.domain.com')

为了确保我不会忘记,我通常会创建一个帮助程序来设置和删除默认域所在的 cookie始终指定。

To set a cookie on specific domain:

cookies[:my_cookie] = {:value => 'Tasty Cookie', :domain => 'www.domain.com'}

One gotcha is that you must also specify the domain when you delete domain-specific cookies:

cookies.delete(:my_cookie, :domain => 'www.domain.com')

To make sure I don't forget, I usually make a helper for setting and deleting cookies where the default domain is always specified.

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