首页 新闻 会员 周边

jquery ajax withCredentials:true 在 Chrome 中不起作用

0
悬赏园豆:50 [已解决问题] 解决于 2019-02-26 21:45

下面的 ajax 请求代码在 Chrome 中运行时 Chrome 总是不发送 Cookie ,而在 Safari 与 Firefox 都正常,请问如何解决这个问题?

$.ajax({
    url: 'xxx',
    type: 'put',
    xhrFields: { withCredentials: true },
    crossDomain: true });
dudu的主页 dudu | 高人七级 | 园豆:31007
提问于:2019-02-26 19:02
< >
分享
最佳答案
0

在 stackoverflow 上找到了答案

Theres new draft on cookie policy, called SameSite, currently implemented by Chrome and Opera.
Basically, cookies marked with SameSite=Strict are not sent with CORS request event if you set xhr.withCredentials = true;
In order to make it work, you have to disable SameSite policy on particular cookie. In case of ASP.NET Core 2.0 authetication cookie it was:

services.AddAuthentication(...)
    .AddCookie(option => option.Cookie.SameSite = SameSiteMode.None)
    .AddOpenIdConnect(...)
dudu | 高人七级 |园豆:31007 | 2019-02-26 21:44
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册