Setting SameSite=None and Secure in ASP.NET

now he who must not be named. picture now he who must not be named. · Feb 5, 2020 · Viewed 16.8k times · Source

Read about the SameSite changes enforced to prevent Cross-Site Forgery. Source: https://blog.chromium.org/2019/10/developers-get-ready-for-new.html

I'm trying to set its value to "None" and use Secure as advertised.

My current web.config setting is as below:

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

Documentation Soure: https://docs.microsoft.com/en-us/dotnet/api/system.web.configuration.sessionstatesection.cookiesamesite?view=netframework-4.8#System_Web_Configuration_SessionStateSection_CookieSameSite

But still I get the below error:

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`.

How do I specify secure attribute in the above web.config file ? Any leads will be much appreciated.

Answer

Guest picture Guest · Feb 6, 2020

According to this link from Microsoft, sessionState doesn't have that attribute so it falls back to the httpCookies section. https://docs.microsoft.com/en-us/aspnet/samesite/system-web-samesite Hope that helps.