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 |