Coldfusion cfscript cookie 不允许空白过期



我试图在CF10中使用cfscript cookie来设置浏览器关闭时应删除的cookie。我可以通过set-header<cfcookie>做到这一点,但无法通过struct cookie方法做到这一点。

有人知道比使用set-header更好的解决方案吗?(保持在cfscript标签内)

<cfscript>
    // Set-Cookie:TEST1=hello; Expires=Sun, 07-Aug-2044 17:51:26 GMT; Path=/; HttpOnly
    cookie.test1 = {value="hello", httponly=true};
    // Set-Cookie:TEST3=hello; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly
    cookie.test3 = {value="hello", httponly=true, expires="0"};
    // Set-Cookie:TEST4=hello; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly
    cookie.test4 = {value="hello", httponly=true, expires="-1"};
    // this throws an exception
    //cookie.test5 = {value="hello", httponly=true, expires=""};
</cfscript>
<!--- Set-Cookie:TEST2=hello2; Path=/; HttpOnly --->
<cfcookie name="test2" value="hello2" httponly="true">

我假设您在测试应用程序时使用的是ChromeFirefox。我最近也遇到了同样的问题。Chrome持久化会话cookie,如果你已经启用了继续从我离开选项从设置。Firefox的情况也类似。我没有在IE上测试过,所以我不能说它的行为。Expires属性在这些情况下不起作用。解决方法是您可以使用max-age属性。您可以在max-age属性中指定cookie的生存时间。它也可以在Chrome和Firefox中运行。IE将max-age属性视为未设置的expires属性。所以它会在浏览器重启时清除cookie。我还没有在Safari上测试过。参考:cookie在firefox中不会过期

cookie在chrome浏览器中不会过期

最新更新