{"id":3497,"date":"2024-11-10T09:46:24","date_gmt":"2024-11-10T01:46:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3497\/"},"modified":"2024-11-10T09:46:24","modified_gmt":"2024-11-10T01:46:24","slug":"jquery-ajax-withcredentialstrue-%e5%9c%a8-chrome-%e4%b8%ad%e5%a4%b1%e6%95%88%ef%bc%9a%e4%b8%ba%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3497\/","title":{"rendered":"jQuery ajax withCredentials:true \u5728 Chrome \u4e2d\u5931\u6548\uff1a\u4e3a\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173104476573699.jpg\" class=\"aligncenter\" title=\"jQuery ajax withCredentials:true \u5728 Chrome \u4e2d\u5931\u6548\uff1a\u4e3a\u4ec0\u4e48\uff1f\u63d2\u56fe\" alt=\"jQuery ajax withCredentials:true \u5728 Chrome \u4e2d\u5931\u6548\uff1a\u4e3a\u4ec0\u4e48\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>jquery ajax withcredentials:true \u5728 chrome \u4e2d\u5931\u6548<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 jquery \u7684 ajax \u8bf7\u6c42\u65f6\uff0c\u5982\u679c\u8bbe\u7f6e\u4e86 withcredentials: true \u5e0c\u671b\u6d4f\u89c8\u5668\u53d1\u9001 cookie\uff0c\u4ee5\u5b9e\u73b0\u8de8\u57df\u8bf7\u6c42\u65f6\u9700\u8981\u643a\u5e26 cookie \u7684\u573a\u666f\uff0c\u5728 chrome \u6d4f\u89c8\u5668\u4e2d\u5374\u59cb\u7ec8\u5931\u6548\uff0c\u800c\u5728 safari \u548c firefox \u4e2d\u53c8\u53ef\u4ee5\u6b63\u5e38\u53d1\u9001 cookie\uff0c\u8fd9\u662f\u5462\uff1f<\/p>\n<p>\u8fd9\u4e0e chrome \u548c opera \u6d4f\u89c8\u5668\u4e2d\u5b9e\u65bd\u7684 samesite cookie \u7b56\u7565\u6709\u5173\u3002\u8be5\u7b56\u7565\u89c4\u5b9a\uff0c\u6807\u8bb0\u4e3a samesite=strict \u7684 cookie \u4e0d\u80fd\u5728 cors \u8bf7\u6c42\u4e2d\u53d1\u9001\uff0c\u5373\u4f7f\u8bbe\u7f6e\u4e86 xhr.withcredentials = true \u4e5f\u662f\u5982\u6b64\u3002<\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u9700\u8981\u5728\u7279\u5b9a\u7684 cookie \u4e0a\u7981\u7528 samesite \u7b56\u7565\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e asp.net core 2.0 \u8eab\u4efd\u9a8c\u8bc1 cookie\uff0c\u53ef\u4ee5\u8fdb\u884c\u4ee5\u4e0b\u64cd\u4f5c\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\u5c06\u7981\u7528\u7279\u5b9a cookie\uff08\u5728\u672c\u4f8b\u4e2d\u4e3a\u8eab\u4efd\u9a8c\u8bc1 cookie\uff09\u7684 samesite \u7b56\u7565\uff0c\u4f7f\u5176\u53ef\u4ee5\u5728 chrome \u4e2d\u901a\u8fc7 ajax.withcredentials \u673a\u5236\u53d1\u9001\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjQuery ajax withCredentials:true \u5728 Chrome \u4e2d\u5931\u6548\uff1a\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 \u5728 chrome \u4e2d\u5931\u6548 \u5728\u4f7f\u7528 jquery \u7684 ajax \u8bf7\u6c42\u65f6\uff0c\u5982\u679c\u8bbe\u7f6e\u4e86 withcredentials: true \u5e0c\u671b\u6d4f\u89c8\u5668\u53d1\u9001 cookie\uff0c\u4ee5\u5b9e\u73b0\u8de8\u57df\u8bf7\u6c42\u65f6\u9700\u8981\u643a\u5e26 cookie \u7684\u573a\u666f\uff0c\u5728 chrome \u6d4f\u89c8\u5668\u4e2d\u5374\u59cb\u7ec8\u5931\u6548\uff0c\u800c\u5728 safari \u548c firefox \u4e2d\u53c8\u53ef\u4ee5\u6b63\u5e38\u53d1\u9001 cookie\uff0c\u8fd9\u662f\u5462\uff1f \u8fd9\u4e0e chrome \u548c opera \u6d4f\u89c8\u5668\u4e2d\u5b9e\u65bd\u7684 samesite cookie \u7b56\u7565\u6709\u5173\u3002\u8be5\u7b56\u7565\u89c4\u5b9a\uff0c\u6807\u8bb0\u4e3a samesite=strict \u7684 cookie \u4e0d\u80fd\u5728 cors \u8bf7\u6c42\u4e2d\u53d1\u9001\uff0c\u5373\u4f7f\u8bbe\u7f6e\u4e86 xhr.withcredentials = true \u4e5f\u662f\u5982\u6b64\u3002 \u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u9700\u8981\u5728\u7279\u5b9a\u7684 cookie \u4e0a\u7981\u7528 samesite \u7b56\u7565\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e asp.net core 2.0 \u8eab\u4efd\u9a8c\u8bc1 cookie\uff0c\u53ef\u4ee5\u8fdb\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a services.AddAuthentication(&#8230;) .AddCookie(option =&gt; [&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-3497","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3497","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=3497"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3497\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}