Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set SameSite value to None in .net 4.5.2?

When redirected back to my site from the third party site user session becoming empty. I have checked Response.Cookies["ASP.NET_SessionId"]; sets new value after redirect. By default, ASP.NET_SessionId it sets as Lax. Any possible way to change SameSite value in Session_Start of .net framework 4.5.2 or possible anywhere?

like image 204
Vaibhav Deshmukh Avatar asked Jun 25 '20 13:06

Vaibhav Deshmukh


People also ask

Should I set SameSite to “none”?

If you’re on .Net 4.7 or higher, Microsoft supports setting SameSite to None. The official recommendation is that if you want to use SameSite None, then you need to move up to .Net 4.7.2, which if you are able, you should absolutely do.

Does the SameSite attribute exist in NET Framework?

In this article .NET Framework 4.7 has built-in support for the SameSiteattribute, but it adheres to the original standard. The patched behavior changed the meaning of SameSite.Noneto emit the attribute with a value of None, rather than not emit the value at all.

What does a value of (samesitemode (-1) mean?

A value of None means "Emit the attribute with a value of None ". A SameSite value of (SameSiteMode) (-1) causes the attribute not to be emitted. The default SameSite value for forms authentication and session state cookies was changed from None to Lax. Summary of change impact on browsers

How to revert the updated SameSite behavior in NET Framework apps?

You can revert the updated sameSite behavior in .NET Framework apps to its previous behavior where the sameSite attribute is not emitted for a value of None, and revert the authentication and session cookies to not emit the value.


1 Answers

Couple options to work around this constraint with older versions of the .net framework

HttpContext.Current.Response.Headers.Append("set-cookie", $"{key}={value}; path=/; SameSite=Strict; Secure");

Is one option for setting the headers manually with the SameSite defined. Above, key is the cookie name, value is the cookie value

Alternatively:

myCookie.Path = "/; SameSite=Strict; Secure";

I've tested these options, both appear to work

Values listed above are for examples only, you will need to supply the appropriate values [Lax|Strict|None|etc]. The Secure flag indicates that its transmitted over https only. Ymmv

like image 90
webbexpert Avatar answered Oct 20 '22 06:10

webbexpert