Adding Same-site; Secure to Cookies in Classic ASP
我们正在运行一个经典的ASP网站,并且在Chrome浏览器中出现Cookies方面的问题。 Chrome强制执行cookie的安全设置(https://www.chromestatus.com/feature/5633521622188032)
我们将cookie设置如下:
1 2 | Response.AddHeader"Set-Cookie","TestCookie=This is a Test; path=/; SameSite=None; Secure" Response.Cookies("TestCookie").Expires = Date + 1 |
但是,Chrome出现问题,当调用其他域的资源时,会话突然结束。
Chrome浏览器的cookie详细信息如下:
1 2 | Send for Same-site connections only |
请注意,正如我认为的那样,没有提到"安全"。
为此,在经典ASP中设置Cookie的正确方法是什么?
您当前的设置响应Cookie的方法存在问题。
使用
测试您的代码,这是Response标头的内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <% Function FormatCookieDateTime(interval, value, tz) Dim dt: dt = DateAdd(interval, value, Date()) Dim tm: tm = Time() Dim result: result = WeekDayName(WeekDay(dt), True) &"," & _ Right("00" & Day(dt), 2) &"-" & _ MonthName(Month(dt), True) &"-" & _ Year(dt) &"" & _ Right("00" & Hour(Time()), 2) &":" & _ Right("00" & Minute(Time()), 2) &":" & _ Right("00" & Second(Time()), 2) &"" & tz FormatCookieDateTime = result End Function Response.AddHeader"Set-Cookie","TestCookie=This is a Test; path=/; SameSite=None; Secure; expires=" & FormatCookieDateTime("d", 1,"GMT") %> |
内置了使使用正确格式设置有效期更容易的功能。
记住
因为您要设置两个cookie(一个通过
This set-cookie had the"Secure" attribute but was not received over a secure connection.
标准的Res??ponse.Cookies方法不能与通过使用更底层的Reponse.Addheader设置的cookie一起可靠地工作。我经历过同样的事情。
我无法测试,但您可能想尝试两件事:
请勿在同一ASP代码块中使用这两个指令。我的猜测是使用
尝试使用相同的
我有一些在线示例代码,使用
https://gitlab.com/erik4/classic-asp-book-examples/-/blob/master/global.asa