{"id":3895,"date":"2024-11-10T17:03:05","date_gmt":"2024-11-10T09:03:05","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3895\/"},"modified":"2024-11-10T17:03:05","modified_gmt":"2024-11-10T09:03:05","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88-jquery-ajax-withcredentialstrue-%e5%9c%a8-chrome-%e4%b8%ad%e6%97%a0%e6%b3%95%e4%ba%a4%e6%8d%a2-cookie%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3895\/","title":{"rendered":"\u4e3a\u4ec0\u4e48 jQuery ajax withCredentials:true \u5728 Chrome \u4e2d\u65e0\u6cd5\u4ea4\u6362 Cookie\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173116116443369.jpg\" class=\"aligncenter\" title=\"\u4e3a\u4ec0\u4e48 jQuery ajax withCredentials:true \u5728 Chrome \u4e2d\u65e0\u6cd5\u4ea4\u6362 Cookie\uff1f\u63d2\u56fe\" alt=\"\u4e3a\u4ec0\u4e48 jQuery ajax withCredentials:true \u5728 Chrome \u4e2d\u65e0\u6cd5\u4ea4\u6362 Cookie\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>jquery ajax withcredentials:true \u95ee\u9898<\/strong><\/p>\n<p>\u95ee\u9898\uff1a<br \/>\u5728 chrome \u6d4f\u89c8\u5668\u4e2d\uff0c\u4f7f\u7528 ajax \u53d1\u9001\u8bf7\u6c42\u65f6\uff0c\u8bbe\u7f6e withcredentials:true \u5374\u65e0\u6cd5\u4e0e\u670d\u52a1\u5668\u4ea4\u6362 cookie\u3002\u5728 safari \u548c firefox \u6d4f\u89c8\u5668\u4e2d\u53ef\u4ee5\u6b63\u5e38\u5de5\u4f5c\u3002\u5982\u4f55\u89e3\u51b3\uff1f<\/p>\n<p>\u7b54\u6848\uff1a<br \/>stack  \u4e0a\u6709\u4e00\u4e2a\u6f5c\u5728\u7684\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p>\u6839\u636e[samesite cookie \u8349\u6848](https:\/\/developer.mozilla.org\/en-us\/docs\/glossary\/samesite_cookie)\uff0c\u7531 chrome \u548c opera \u5b9e\u73b0\uff0c\u88ab\u6807\u8bb0\u4e3a samesite=strict \u7684 cookie \u4e0d\u968f\u540c\u8de8\u57df\u8bf7\u6c42\u53d1\u9001\uff0c\u5373\u4f7f\u5df2\u8bbe\u7f6e xhr.withcredentials = true\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\uff1a<br \/>\u7981\u7528\u7279\u5b9a cookie \u7684 samesite \u7b56\u7565\u3002\u4f8b\u5982\uff0c\u5728 asp.net core 2.0 \u4e2d\uff0c\u5bf9\u8ba4\u8bc1 cookie \u542f\u7528\u76f8\u540c\u7684\u7b56\u7565\uff1a<\/p>\n<pre>services.AddAuthentication(...)\n    .AddCookie(option =&gt; option.Cookie.SameSite = SameSiteMode.None)\n    .AddOpenIdConnect(...)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f jQuery ajax withCredentials:true \u5728 Chrome \u4e2d\u65e0\u6cd5\u4ea4\u6362 Cookie\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>jquery ajax withcredentials:true \u95ee\u9898 \u95ee\u9898\uff1a\u5728 chrome \u6d4f\u89c8\u5668\u4e2d\uff0c\u4f7f\u7528 ajax \u53d1\u9001\u8bf7\u6c42\u65f6\uff0c\u8bbe\u7f6e withcredentials:true \u5374\u65e0\u6cd5\u4e0e\u670d\u52a1\u5668\u4ea4\u6362 cookie\u3002\u5728 safari \u548c firefox \u6d4f\u89c8\u5668\u4e2d\u53ef\u4ee5\u6b63\u5e38\u5de5\u4f5c\u3002\u5982\u4f55\u89e3\u51b3\uff1f \u7b54\u6848\uff1astack \u4e0a\u6709\u4e00\u4e2a\u6f5c\u5728\u7684\u89e3\u51b3\u65b9\u6848\uff1a \u6839\u636e[samesite cookie \u8349\u6848](https:\/\/developer.mozilla.org\/en-us\/docs\/glossary\/samesite_cookie)\uff0c\u7531 chrome \u548c opera \u5b9e\u73b0\uff0c\u88ab\u6807\u8bb0\u4e3a samesite=strict \u7684 cookie \u4e0d\u968f\u540c\u8de8\u57df\u8bf7\u6c42\u53d1\u9001\uff0c\u5373\u4f7f\u5df2\u8bbe\u7f6e xhr.withcredentials = true\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a\u7981\u7528\u7279\u5b9a cookie \u7684 samesite \u7b56\u7565\u3002\u4f8b\u5982\uff0c\u5728 asp.net core 2.0 \u4e2d\uff0c\u5bf9\u8ba4\u8bc1 cookie \u542f\u7528\u76f8\u540c\u7684\u7b56\u7565\uff1a services.AddAuthentication(&#8230;) .AddCookie(option =&gt; option.Cookie.SameSite = SameSiteMode.None) .AddOpenIdConnect(&#8230;) \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0a\u5c31\u662f jQuery ajax withCredentials:true [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3895","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3895","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3895"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3895\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}