【问题标题】:How can I restrict some subdomains in cookie?如何限制 cookie 中的某些子域?
【发布时间】:2020-03-11 14:36:13
【问题描述】:

假设我的网站位于不同的域中,例如: - sub1.domain.com - sub2.domain.com - 域名.com

那么,我怎样才能限制 sub2.domain.com 的 cookie,但同时允许 sub1.domain.com 和 domain.com 使用它?

【问题讨论】:

标签: java http servlets cookies httpcookie


【解决方案1】:

只有在 Set-Cookie 标头中明确命名了域时,这 2 个域 domain.com 和 sub1.domain.com 才能共享 cookie。否则,cookie 的范围仅限于请求主机。 (称为“主机专用 cookie”)

如果您从 sub1.domain.com 发送了以下标头,则 cookie 将不会发送给 domain.com 的请求:

Set-Cookie: name=value

但是,如果您使用以下内容,它将在两个域中都可用:

Set-Cookie: name=value; domain=domain.com

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-11
    • 1970-01-01
    • 1970-01-01
    • 2017-11-04
    • 2012-05-13
    • 1970-01-01
    相关资源
    最近更新 更多