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

now*_*ed. 3 c# asp.net cookies web-config samesite

阅读有关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>
Run Code Online (Sandbox Code Playgroud)

文档来源: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`.
Run Code Online (Sandbox Code Playgroud)

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

小智 5

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

  • 那么,我们应该回退并在 web.config 中使用类似 `&lt;httpCookies requireSSL="true"&gt;` 的内容吗? (2认同)