{"id":3361,"date":"2024-11-10T16:35:00","date_gmt":"2024-11-10T08:35:00","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3361\/"},"modified":"2024-11-10T16:35:00","modified_gmt":"2024-11-10T08:35:00","slug":"chrome-%e6%b5%8f%e8%a7%88%e5%99%a8%e4%b8%ad%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3jquery-ajax-withcredentialstrue-%e5%a4%b1%e6%95%88%e9%97%ae%e9%a2%98%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3361\/","title":{"rendered":"Chrome \u6d4f\u89c8\u5668\u4e2d\u5982\u4f55\u89e3\u51b3jQuery ajax withCredentials:true \u5931\u6548\u95ee\u9898\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173103354349875.jpg\" class=\"aligncenter\" title=\"Chrome \u6d4f\u89c8\u5668\u4e2d\u5982\u4f55\u89e3\u51b3jQuery ajax withCredentials:true \u5931\u6548\u95ee\u9898\uff1f\u63d2\u56fe\" alt=\"Chrome \u6d4f\u89c8\u5668\u4e2d\u5982\u4f55\u89e3\u51b3jQuery ajax withCredentials:true \u5931\u6548\u95ee\u9898\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 chrome \u4e2d\u89e3\u51b3 jquery ajax withcredentials:true \u5931\u6548\u95ee\u9898<\/strong><\/p>\n<p>\u5728\u8de8\u57df\u8bf7\u6c42\u4e2d\u4f7f\u7528 jquery ajax \u65f6\uff0cwithcredentials:true \u9009\u9879\u901a\u5e38\u80fd\u591f\u53d1\u9001 cookie \u51ed\u636e\u3002\u7136\u800c\uff0c\u4e00\u4e9b\u7528\u6237\u62a5\u544a\u79f0\u6b64\u9009\u9879\u5728 chrome \u4e2d\u65e0\u6548\u3002<\/p>\n<p>\u8fd9\u4e2a\u95ee\u9898\u7684\u539f\u56e0\u5728\u4e8e chrome \u4e2d\u5b9e\u65bd\u4e86\u79f0\u4e3a samesite \u7684\u65b0 cookie \u7b56\u7565\u3002samesite=strict \u6807\u8bb0\u7684 cookie \u4e0d\u4f1a\u5728\u8de8\u57df\u8bf7\u6c42\u4e2d\u53d1\u9001\uff0c\u5373\u4f7f\u8bbe\u7f6e\u4e86 xhr.withcredentials = true\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u5fc5\u987b\u5728\u9700\u8981\u53d1\u9001 cookie \u7684\u7279\u5b9a cookie \u4e0a\u7981\u7528 samesite \u7b56\u7565\u3002\u5bf9\u4e8e asp.net core 2.0 \u8eab\u4efd\u9a8c\u8bc1 cookie\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728 startup.cs \u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u6765\u5b9e\u73b0\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>\u8fd9\u6837 chrome \u6d4f\u89c8\u5668\u5c31\u4e0d\u4f1a\u963b\u6b62 cookie \u7684\u53d1\u9001\uff0cwithcredentials:true \u9009\u9879\u5c06\u6b63\u5e38\u5de5\u4f5c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fChrome \u6d4f\u89c8\u5668\u4e2d\u5982\u4f55\u89e3\u51b3jQuery ajax withCredentials:true \u5931\u6548\u95ee\u9898\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>\u5982\u4f55\u5728 chrome \u4e2d\u89e3\u51b3 jquery ajax withcredentials:true \u5931\u6548\u95ee\u9898 \u5728\u8de8\u57df\u8bf7\u6c42\u4e2d\u4f7f\u7528 jquery ajax \u65f6\uff0cwithcredentials:true \u9009\u9879\u901a\u5e38\u80fd\u591f\u53d1\u9001 cookie \u51ed\u636e\u3002\u7136\u800c\uff0c\u4e00\u4e9b\u7528\u6237\u62a5\u544a\u79f0\u6b64\u9009\u9879\u5728 chrome \u4e2d\u65e0\u6548\u3002 \u8fd9\u4e2a\u95ee\u9898\u7684\u539f\u56e0\u5728\u4e8e chrome \u4e2d\u5b9e\u65bd\u4e86\u79f0\u4e3a samesite \u7684\u65b0 cookie \u7b56\u7565\u3002samesite=strict \u6807\u8bb0\u7684 cookie \u4e0d\u4f1a\u5728\u8de8\u57df\u8bf7\u6c42\u4e2d\u53d1\u9001\uff0c\u5373\u4f7f\u8bbe\u7f6e\u4e86 xhr.withcredentials = true\u3002 \u89e3\u51b3\u65b9\u6848 \u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u5fc5\u987b\u5728\u9700\u8981\u53d1\u9001 cookie \u7684\u7279\u5b9a cookie \u4e0a\u7981\u7528 samesite \u7b56\u7565\u3002\u5bf9\u4e8e asp.net core 2.0 \u8eab\u4efd\u9a8c\u8bc1 cookie\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728 startup.cs \u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u6765\u5b9e\u73b0\uff1a services.AddAuthentication(&#8230;) .AddCookie(option =&gt; option.Cookie.SameSite = SameSiteMode.None) .AddOpenIdConnect(&#8230;) \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u6837 chrome \u6d4f\u89c8\u5668\u5c31\u4e0d\u4f1a\u963b\u6b62 [&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-3361","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3361","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=3361"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3361\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}