簡體   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