简体   繁体   English

在 Cookie 中保存动态 CultureInfo 的 Blazor 服务器应用程序在 iFrame 中不起作用

[英]Blazor Server App with Dynamic CultureInfo Saved in Cookie don't work in iFrame

I can't share my own app for nda issue but I found this one which shows exactly the same issue我无法为 nda 问题分享我自己的应用程序,但我发现这个显示完全相同的问题

https://github.com/SyncfusionExamples/blazor-localization/tree/master/.NET6%20Blazor%20Server%20App/Localization-with-dynamic-culture Blazor-Localization https://github.com/SyncfusionExamples/blazor-localization/tree/master/.NET6%20Blazor%20Server%20App/Localization-with-dynamic-culture Blazor-Localization

This app displays a page with a CultureSwitcher component to select between 5 languages.这个应用程序显示一个带有CultureSwitcher组件的页面,可以在 5 种语言之间进行选择。

When you select a language, I can see both the page+dropdown refreshed with the selected language value.当您选择一种语言时,我可以看到页面+下拉菜单都使用所选语言值刷新。

Now, you embed the Url of this app inside a new app's page inside an iFrame and nothing works anymore.现在,您将此应用程序的 URL 嵌入到 iFrame 内的新应用程序页面中,并且不再起作用。

The cookie mechanism doesn't save or/and load the value anymore. cookie 机制不再保存或/和加载值。

This was working perfectly in net+core+3.1 and 5.0 but no more in net+core+6.这在 net+core+3.1 和 5.0 中运行良好,但在 net+core+6 中不再有效。

Is something change in security or cors or ????安全性或 cors 是否有变化或 ????

Thanks in advance for any tips提前感谢您的任何提示

-Vince -文斯

This sounds like an issue with SameSite cookies.这听起来像是 SameSite cookie 的问题。 It's even documented here :它甚至记录在这里

Applications that use <iframe> may experience issues with sameSite=Lax or sameSite=Strict cookies because is treated as cross-site scenarios.使用 <iframe> 的应用程序可能会遇到有关 sameSite=Lax 或 sameSite=Strict cookie 的问题,因为它被视为跨站点方案。

Have you tried setting the cookie options?您是否尝试过设置 cookie 选项?

HttpContext.Response.Cookies.Append(
    CookieRequestCultureProvider.DefaultCookieName,
    CookieRequestCultureProvider.MakeCookieValue(
       new RequestCulture(culture)),
    new CookieOptions() { SameSite = SameSiteMode.None, Secure = true} );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM