繁体   English   中英

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

[英]Setting SameSite=None and Secure in ASP.NET

阅读有关为防止跨站点伪造而强制执行的SameSite更改。 来源: https : //blog.chromium.org/2019/10/developers-get-ready-for-new.html

我正在尝试将其值设置为“无”并按照宣传的方式使用Secure

我当前的web.config设置如下:

<system.web>
    <sessionState cookieless="UseCookies" 
       timeout="20" 
       cookieSameSite="None" 
       xdt:Transform="Replace" 
       xdt:Locator="Match(cookieless)"/>
  </system.web>

文档来源: https ://docs.microsoft.com/en-us/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属性? 任何线索将不胜感激。

根据微软的这个链接, sessionState 没有那个属性,所以它回退到 httpCookies 部分。 https://docs.microsoft.com/en-us/aspnet/samesite/system-web-samesite希望有所帮助。

您还可以根据 cookie 创建进行设置

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

暂无
暂无

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

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