Usage and time settings for ASP cookies

Source: Internet
Author: User

The Response.Cookies command is used to create cookies.

Note: The Response.Cookies command must precede the

In the following example, we create a cookie named "FirstName" and assign it to "Alex":

The code is as follows Copy Code

<%
Response.Cookies ("firstname") = "Alex"
%> It is also possible to assign properties to cookies, such as setting the expiration time of a cookie:

<%
Response.Cookies ("firstname") = "Alex"
Response.Cookies ("FirstName"). expires= #May 10,2020#
%>

Specific cookie Time settings

The code is as follows Copy Code
Response.Cookies ("field name"). expires= time function +n, for example:
Response.Cookies ("field name"). Expires=date+1, which means that Cookies are kept for 1 days, and then for example:
Response.Cookies ("field name"). Expires=hour+8, which means Cookies are kept for 8 hours.
Response.Cookies ("field name"). Expires=minute+8, which means Cookies are kept for 8 minutes.

The above set some test does not work, suggest or use DateAdd function, for example we want to add an hour, then use:
Response.Cookies ("Baidooglecom"). Expires = DATEADD ("h", 1, Now ())
30 minutes:

The code is as follows Copy Code
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 in January 1, 2010:

The code is as follows Copy Code
Response.Cookies ("CookieName"). expires= #January 01, 2010#

The expiration time for the cookie is "create time of Cookie + 365 days":

The code is as follows Copy Code
Response.Cookies ("CookieName"). expires=date+365

But it's best not to write.
Response.Cookies ("CookieName"). Expires=date, so that the call value between pages is empty.

Read all cookie values

The code is as follows Copy Code

<body>

<%
Dim x,y

 for each x in Request.Cookies
  Response.Write ("< P> ")
  if Request.Cookies (x). HasKeys then
    for all y in Request.Cookies (x)
      Response.Write ( X & ":" & Y & "=" & Request.Cookies (x) (y))
      Response.Write ("<br/> ;")
    Next
  Else
    Response.Write (x & "=" & Request.Cookies (x) & Amp "<br/>")
  End If
  Response.Write "</p>"
Next
%>

</body>
< /html> output:

Firstname=alex

User:firstname=john
User:lastname=adams
User:country=uk
User: age=25

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.