In Google Chrome console I am getting this warning "A cookie associated with a cross-site resource at "URL" was set without the SameSite
attribute". It has been blocked, as Chrome now only delivers cookies with cross-site requests if they are set with SameSite=None
and Secure
.
I verified the same under Application>Storage>Cookies their I found Same Site was "blank/Empty" and I want to update that into "None".
Tried some of the ways mentioned by other developers but nothing seems to be working for me.
Implementation 1: Updated my web.config with below mentioned code
<sessionState cookieSameSite="None" />
<httpCookies httpOnlyCookies="true" requireSSL="true" />
// sameSite="None" is not coming for me under httpCookies section and giving me a error message sameSite attribute is not allowed
Implementation 2: Modifed class file code where I am creating that Cookie
HttpCookie sessionCookie = new HttpCookie("Token");
sessionCookie.Value = sessionToken;
sessionCookie.HttpOnly = true;
sessionCookie.SameSite = SameSiteMode.None;
sessionCookie.Secure = FormsAuthentication.RequireSSL && Request.IsSecureConnection;
sessionCookie.Domain = Request.Url.Host;
Response.Cookies.Add(sessionCookie);
Implementation 3: Created a seperate MVC filter to Handle this
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var response = filterContext.RequestContext.HttpContext.Response;
if (response != null)
{
response.AddHeader("Set-Cookie", "HttpOnly;Secure;SameSite=None");
}
base.OnActionExecuting(filterContext);
}
Implementation 4:
<rewrite>
<outboundRules>
<rule name="Add SameSite" preCondition="No SameSite">
<match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="false" />
<action type="Rewrite" value="{R:0}; SameSite=None" />
<conditions>
</conditions>
</rule>
<preConditions>
<preCondition name="No SameSite">
<add input="{RESPONSE_Set_Cookie}" pattern="." />
<add input="{RESPONSE_Set_Cookie}" pattern="; SameSite=" negate="true" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
Target .net Framework 4.7.2
Is there anything I need to do in my local machine or server or anyway by which I can remove this warning message.