【问题标题】:Chrome Set Cross Domain CookieChrome 设置跨域 Cookie
【发布时间】:2017-10-06 16:31:06
【问题描述】:

我的网站是 a.com,我想在 b.com 中创建一个 cookie。

我尝试使用对 b.com 的 ajax 请求设置跨域 cookie 并返回设置的 cookie 标头。 如果我直接访问 b.com 会设置 cookie,但它不会通过 ajax 请求设置它,尽管我在开发人员工具中看到了 cookie set 命令。 iframe 不是一个选项,因为我在 post 请求中发送 cookie 数据

【问题讨论】:

  • 您不能设置“跨域”cookie。 Cookie 是域绑定的,只有原始域才能为该域设置 cookie。
  • 我知道,但我向 b.com 发送了 ajax 请求,b.com 告诉浏览器为 b.com 设置 cookie。我在这里没有看到安全问题。使用 iframe 也可以实现同样的目的

标签: ajax asp.net-mvc cookies web


【解决方案1】:

对于 XHR 请求,您需要将 withCredentials 设置为 true

$.ajax({
   url: a_cross_domain_url,
   xhrFields: {
      withCredentials: true
   }
});

【讨论】:

    猜你喜欢
    • 2017-06-09
    • 2021-08-15
    • 2017-03-30
    • 2011-01-20
    • 2011-02-05
    • 2015-09-18
    • 2015-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多