问题描述
Chrome 76将开始支持显式的SameSite: None
属性
Chrome 76 will begin to support an explicit SameSite: None
attribute
https://web.dev/samesite-cookies-explained/
我发现ASP.NET Core的当前实现将SameSiteMode.None
视为无操作,并且不发送任何属性.如何将自定义属性添加到Cookie,从而在Cookie文本中添加显式SameSite: None
?
I found that the current implementation of ASP.NET Core treats SameSiteMode.None
as a no-op and does not send any attribute. How can I add a custom attribute to a cookie and thereby add an explicit SameSite: None
to the cookie text?
将属性附加到cookie值不能像HttpResponse.Cookies.Append url那样对cookie值进行编码.
Appending the attribute to the cookie value does not work as HttpResponse.Cookies.Append url-encodes the cookie value.
推荐答案
现在已在所有版本的.NET Framework和.NET Core( https://github.com/aspnet/AspNetCore/issues/12125 )
It's now fixed in latest release of all versions of .NET Framework and .NET Core (https://github.com/aspnet/AspNetCore/issues/12125)
我在.NET Core 2.2上运行了多个项目,升级到2.2.207之后,我再也没有问题了.
I have multiple projects running on .NET Core 2.2 and after upgrading to 2.2.207, I don't have the problem anymore.
此处是Startup.cs
文件的ConfigureServices
方法中存在的示例代码
Here a sample code present in ConfigureServices
method of Startup.cs
file
services.ConfigureApplicationCookie(options => {
options.Cookie.SameSite = SameSiteMode.None;
);
这篇关于如何将SameSite Cookie属性设置为显式ASP ASP.NET Core的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!