在ASP.NET中设置SameSite=None和Secure

3
阅读关于强制执行SameSite更改以防止跨站点伪造的内容。 来源:https://blog.chromium.org/2019/10/developers-get-ready-for-new.html 我正在尝试将其值设置为“None”并使用如广告中所述的Secure
我的当前 web.config 设置如下:
<system.web>
    <sessionState cookieless="UseCookies" 
       timeout="20" 
       cookieSameSite="None" 
       xdt:Transform="Replace" 
       xdt:Locator="Match(cookieless)"/>
  </system.web>

文档来源: https://learn.microsoft.com/zh-cn/dotnet/api/system.web.configuration.sessionstatesection.cookiesamesite?view=netframework-4.8#System_Web_Configuration_SessionStateSection_CookieSameSite

但我仍然收到以下错误:

A cookie associated with a resource at `mywebsite.net` was set with `SameSite=None` but without `Secure`. A future release of Chrome will only deliver cookies marked `SameSite=None` if they are also marked `Secure`.

我该如何在上述 web.config 文件中指定 secure 特性?任何线索将不胜感激。

2个回答

5

2
那么,我们应该退而使用类似于 <httpCookies requireSSL="true"> 在 web.config 中吗? - now he who must not be named.
是的,YES是对那个评论问题的答案。 - Oliver

0

你也可以根据每个cookie的创建来设置它

using SameSiteMode = Microsoft.AspNetCore.Http.SameSiteMode;
....
context.HttpContext.Response.Cookies.Append(cookie.Key, cookie.Value,
 new CookieOptions { SameSite = SameSiteMode.None,Secure = true });

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接