
jquery ajax withcredentials:true 在 chrome 中失灵
在某些情况下,在 chrome 中使用 jquery ajax 发出跨域请求时,即使设置了 xhrfields: { withcredentials: true },也不会发送 cookie。这个问题在 safari 和 firefox 中不会出现。
原因
问题出在一个名为 samesite 的新 cookie 策略,目前 chrome 和 opera 已实施该策略。根据此策略,标记为 samesite=strict 的 cookie 在设置 xhr.withcredentials = true 时不会随 cors 请求一起发送。
解决方案
为了解决此问题,需要禁用于特定 cookie 的 samesite 策略。对于 asp.net core 2.0 身份验证 cookie,可以这样操作:
services.AddAuthentication(...)
.AddCookie(option => option.Cookie.SameSite = SameSiteMode.None)
.AddOpenIdConnect(...)以上就是jQuery ajax withCredentials:true 在 Chrome 中失灵:为什么我的跨域请求没有发送 Cookie?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号