cookies - 未在 iframe 中设置 Cookie

标签 cookies iframe asp.net-core identityserver4 c3.js

我在一台服务器上有一个身份服务器 (v4),在不同的服务器和域上有一个 Web 应用程序。我只需要 Windows 身份验证,一切都可以通过重定向正常工作。但是,我注意到如果 cookie 尚未过期,则静默登录有效。

如果 cookie 已过期,则当前需要重定向,这可以正常工作。然而不幸的是,这意味着如果用户没有在当前屏幕上保存数据,除非我实现缓存机制,否则他们将丢失它。相反,我想设置一个隐藏的 iframe,它只是导航到身份服务器,如果用户在公司基础设施内(他们总是这样),则自动登录。

经过数小时的调试,我发现虽然 cookie 是从 iFrame 正确发送的,但任何 SET 似乎都不起作用 - 它们在 chrome 调试器中作为响应 cookie,但不会在下一次重定向时作为请求 cookie 发送我不知道为什么。

在回应:

Cookie Options: SameSite Lax, HTTP true, Secure true, Path /

Headers:

Content-Security-Policy: default-src 'self'; object-src 'none'; frame-src localhost:44388; frame-ancestors 'self' https://localhost:44388/; sandbox allow-forms allow-same-origin allow-scripts; base-uri 'self';

Persistent-Auth: true

Pragma: no-cache

Referrer-Policy: no-referrer

WWW-Authenticate: Negotiate oRswGaADCgEAoxIEEAEAAABJ+0p/zH0aeAAAAAA=

X-Content-Security-Policy: default-src 'self'; object-src 'none'; frame-src **localhost:44388; frame-ancestors 'self' https://localhost:44388/; sandbox allow-forms allow-same-origin allow-scripts; base-uri 'self';

X-Content-Type-Options: nosniff

X-Frame-Options: ALLOW-FROM https://localhost:44388/

最佳答案

从 2020 年 8 月起,您必须将 SameSite 设置为无,并将安全设置为 True。
在 php 中可以用以下方法完成:
setcookie("变量", 1, time() + (86400), "/ ; SameSite=None; Secure ");
在 javascript 中路径选项之后将是类似的。
document.cookie="cookiename="+0+";Domain=.yourdomain.net; path=/; SameSite=None; Secure"

关于cookies - 未在 iframe 中设置 Cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51151183/

相关文章:

.net - .net core 3.1 web api 中的多个 get 方法

cookies - 为什么我的 localhost 项目上会出现 _ga cookie?

删除 JSESSIONID cookie 的 JavaScript 不起作用

asp.net-core - 如何在 Linux Ubuntu 16.04 上运行的 ASPNET Core 中正确使用 ImageMagick.NET?

html - 对 YouTube iframe 使用无缝和/或沙盒属性有什么意义吗?

javascript - 移动 iframe youtube 查看尝试下载但不显示视频

asp.net-core - 如何在 ASP.NET Core 的 OpenIdConnectOptions 上设置 redirect_uri 参数

c# - 为什么不在 ASP.NET Web 表单中使用 Request.Cookies.Clear()?

ios - Mobile Safari 在硬重置时清除 cookie 和 LocalStorage

javascript - 调整视频iframe的高度