ASP Set Cookies Expiration time

Source: Internet
Author: User

Response.Cookies ("user_name"). expires=date+1  ' Specify cookie save time  

Keep cookies one hour  
Response.Cookies ("MyCookie"). expires=  (now () +1/24)  

Response.Cookies ("MyCookie"). Expires = dateadd ("H",  1, now ())  


Response.Cookies ("CookieName"). Expires=dateadd ("M", 60,now ())  
Set expires after 60 months  

Response.Cookies ("User"). Expires=second () +7  
The time defined after expires can be replaced with a time function  
For example: date () +7 means adding 7 days to today's time, while second () +7 is 7 seconds.  

Response.Cookies (field name). expires= Time function +n, such as: 
Response.Cookies ("name2"). expires=date+ 1, which means that cookies are kept for 1 days, and then: 
Response.Cookies ("name2"). Expires=hour+8, which means cookies are kept for 8 hours.  
This method I have not tested (in 2003server,iis6.0), regardless of the second after the addition (), access to a 500 error (or the page can not be displayed?) Forgotten).  


Dream Juventus: Here's the time to add to the suggestion or use the DateAdd function, such as we want to add an hour, then use: 
Response.Cookies ("baidooglecom"). Expires = dateadd ("H",  1, now ())  

30 minutes: 
RespoNse. Cookies ("CookieName"). Expires=dateadd ("n", 30,now ())  

DateAdd ("S", 30,now ())   Get seconds  


expires  Specify The  cookie  expiration date. In order to store the  cookie  on the client disk after the session is over, or in many cases, we want to save the cookie for a longer time on the visitor's computer. The date must be set.  
If the setting of this property does not exceed the current date, the  cookie  expires after the task ends.  
The use of the cookie expires in January 1, 2010:  response.cookies ("CookieName"). expires= #January  01, 2010# 
The expiration Time for cookies is "creation time of Cookie + 365 days": Response.Cookies ("CookieName"). expires=date+365  recommended
But it is best not to write  response.cookies ("CookieName") casually. Expires=date, so that the call value between pages is empty.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.