Search code examples
cookiesasp-classic

Setting expires on asp cookies with keys won't work


I have a login page written in classic asp. I want to set the users login information into asp cookies so the next time they arrive at the page they stay logged in for a period of 2 weeks.

The problem is when I set an expiry on the cookie which contains keys the cookies don't persit when the browser is closed.

Here is an example of my code:

response.cookies("user")("userId")=userId
response.cookies("user")("firstName")=firstName
response.cookies("user")("lastName")=lastName
response.cookies("user").expires=dateadd("d",14,now)

Setting a cookie without keys works, but when using keys expires doesn't work.

Can anyone help me with this issue?

Ben


Solution

  • This should work... just move the expiration to be the first value you set for the key:

    response.cookies("user").expires=dateadd("D",14,Date())
    response.cookies("user")("userId") = userId
    response.cookies("user")("firstName") = firstName
    response.cookies("user")("lastName") = lastName