问题描述
根据Google chrome的最新更新。我的网站无法使Google Chrome 84版上的Cookie失效。 得到以下警告
根据我的某些研究,需要使用 false 和 None 更新Cookie属性安全和 SameSite >分别。
问题是SameSite属性在c#dot net 4.5.2中不可用
HttpCookie cookie = new HttpCookie(name);
cookie.Secure = true;
如何实现这一目标。预先感谢。
解决方法
您应该为您的请求添加一个新的独特的hader。使用默认标头时,浏览器会考虑向服务器发送相同的请求。但是,当您为请求提供唯一的标头时,您的问题将会解决。所有请求都将不同。
查看此代码,您可以在Set-Cookie Headers中找到更多代码。
public void ProcessRequest(HttpContext context)
{
HttpRequest request = context.Request;
HttpResponse response = context.Response;
// If ClearHeaders is used Set-Cookie header gets removed!
// if commented header is sent...
response.ClearHeaders();
response.ClearContent();
// Demonstrate that other headers make it
response.AppendHeader("RequestId","asdasdasd");
// This cookie gets removed when ClearHeaders above is called
// When ClearHEaders is omitted above the cookie renders
response.AppendHeader("Set-Cookie","WWTHREADSID=ThisIsThEValue; path=/");
// *** This always works,even when explicit
// Set-Cookie above fails and ClearHeaders is called
//response.Cookies.Add(new HttpCookie("WWTHREADSID","ThisIsTheValue"));
response.Write(@"Output was created.<hr/>
Check output…");
}