How to set cookies expiration time by ASP

Source: Internet
Author: User
Tags add date empty
But it's best not to write Response.Cookies ("CookieName") casually. Expires=date, so that the call value between pages is empty.

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

Keep cookies for one hours
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, and second () +7 is 7 seconds.

Response.Cookies ("field name"). expires= time function +n, for example:
Response.Cookies ("Name2"). Expires=date+1, which means that Cookies are kept for 1 days, and then for example:
Response.Cookies ("Name2"). Expires=hour+8, which means Cookies are kept for 8 hours.
I have not tested this method (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-weaving Juve: Here's the time to add 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 Specifies the expiration date for the cookie. In order to store cookies on the client disk after the session is over, or at many times, we want to save cookies on the visitor's computer for a long time. The date must be set.
If the setting for this property does not exceed the current date, the cookie expires after the task ends.
The use of the cookie expires with "January 1, 2010": Response.Cookies ("CookieName"). expires= #January 01, 2010#
The expiration time for the cookie is "cookie creation time + 365 days": Response.Cookies ("CookieName"). Expires=date+365 recommended.
But it's best not to write Response.Cookies ("CookieName") casually. Expires=date, so that the call value between pages is empty.



Related Article

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.