REPOST: Expiration of Cookies

Results 1 to 3 of 3

Thread: REPOST: Expiration of Cookies

  1. #1
    Branton Boehm Guest

    Default REPOST: Expiration of Cookies

    Sorry to repost, but I think the thread got buried. I&#039;m trying to set the expiration date of my cookies so that my users don&#039;t have to login everytime they visit my site. I kept getting errors and the following code was suggested:<BR><BR>var d = new Date() <BR>d.setDate(d.getDate()+1) <BR>Response.Cookies("whatever").expires = d.toString()<BR><BR>However, I&#039;m getting the following error with the above code:<BR><BR>8/1/2001 9:59:35 PM <BR>Microsoft JScript runtime (0x800A000D) <BR>Type mismatch <BR>/Log/processlogin.asp, line 61<BR><BR>Does anyone know the correct way to set the expiration of cookies using JScript?

  2. #2
    Join Date
    Dec 1969

    Default RE: REPOST: Expiration of Cookies

    get your JScript date object into a format that can be cast by IIS into a cookie expiration. IIS can handle dd/mm/yy type syntax, so just concatenate getDate(), getMonth(), getYear() appropriately.<BR><BR>NB it&#039;s best to use the name of the month rather than the number. I have a little function that returns the right string for the getMonth() number. quite simple to do with a little array<BR><BR>the format "8 August 2001" will work perfectly.<BR><BR>j<BR><BR>(lots of JScript ASP tutorials)

  3. #3
    Branton Boehm Guest

    Default RE: REPOST: Expiration of Cookies

    Thanks a lot. I knew I needed a particular format... just didn&#039;t know which one. Also, thanks for the link. It&#039;s hard finding decent JScript sites.<BR><BR>I think I&#039;m going about my cookie problem wrong, though. The idea is that I&#039;ll save the cookies for a week so that the user doesn&#039;t have to log back in every time he visits the site. Here&#039;s the code I&#039;m using to set the expiration:<BR><BR>if (strGetStringField(Request.Form("RememberInfo")) != "") {<BR>&nbsp;&nbsp;var dtmExpires = new Date();<BR>&nbsp;&nbsp;dtmExpires.setDate(dtmExpir es.getDate() + 7);<BR>&nbsp;&nbsp;var strExpires = strFormatCookieDate(dtmExpires);<BR>&nbsp;&nbsp;Re sponse.Cookies("User").Expires = strExpires;<BR>&nbsp;&nbsp;Response.Cookies("Team" ).Expires = strExpires;<BR>}<BR><BR>It runs with no errors. However, once I login and this code is run, I try closing my browser and coming back to the site. What do you know... Request.Cookies("User") is an empty string.<BR><BR>Do you know what I&#039;m doing wrong? I&#039;m sure it&#039;s something simple, but this is the first time I&#039;ve messed with expirations.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts