Coldfusion cfscript cookie不允许空白到期

时间:2014-08-15 18:03:09

标签: cookies coldfusion cfml

我试图在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">

1 个答案:

答案 0 :(得分:1)

我认为您在测试应用程序时使用的是 Chrome Firefox 。 我最近遇到了同样的问题。如果您已从设置中启用从我停止的位置继续选项,则Chrome会保留会话Cookie。这个案例与Firefox类似。我还没有在IE上测试它,所以我不能说它的行为。 Expires属性在这些情况下不起作用。 解决方法是您可以使用 max-age 属性。您可以在max-age属性中为cookie提供生存时间。 它可以在Chrome和Firefox中使用。 IE将max-age属性视为未设置的expires属性。所以它会在浏览器重启时清除cookie。我还没有在Safari上测试它。 供参考:cookie does not expire in firefox

cookie does not expire in chrome

相关问题