Set cookies in ASP, do not know if this cookie has time limit?

Source: Internet
Author: User
Tags date set cookie time limit domain
Cookie cookies<br>
The Cookies collection sets the value of a cookie. If The specified cookie does not exist, it is created. If The cookie exists, it takes the new value and the old value is discarded.<br>
<br>
Syntax<br>
Response.Cookies (cookie) [(key) |. Attribute] = value <br>
<br>
<br>
<br>
Parameters<br>
Cookies <br>
The name of the cookie.<br>
<br>
Key <br>
An optional parameter. If key is specified, cookies are a dictionary, and key is set to Value.<br>
<br>
Attribute <br>
Specifies information about the cookie itself. The attribute parameter can be one of the following. Name Description <br>
Domain write-only. If specified, the cookie is sent only to requests to this domain. <br>
Expires write-only. The date on which the cookie expires. This date must is set in order for the "cookie" stored on the client's disk after the session ends. If It is not set to a date beyond the current date, the cookie would expire the session ends. <br>
HasKeys read-only. Specifies whether the cookie contains keys. <br>
Path write-only. If specified, the cookie is sent only to requests to this path. The If is not set, the application path is used. <br>
Secure write-only. Specifies whether the cookie is secure. <br>
<br>
<br>
<br>
Value <br>
Specifies the value to assign to key or attribute. <br>
Remarks<br>
If a cookie with a key was created, as in the following script,<br>
<br>
<% <br>
Response.Cookies ("MyCookie") ("type1") = "Sugar" <br>
Response.Cookies ("MyCookie") ("type2") = "ginger Snap" <br>
%> <br>
<br>
This header is sent:<br>
<br>
Set-cookie:mycookie=type1=sugar&type2=ginger+snap<br>
<br>
A subsequent assignment to MyCookie without specifying a key, would destroy and type1. This is shown in the following example.<br>
<br>
<% response.cookies ("MyCookie") = "Chocolate Chip"%> <br>
<br>
In the preceding example, the keys type1 and type2 are destroyed and their values are. The MyCookie cookie now has the value chocolate chip. <br>
<br>
Conversely, if you call a cookies with a key, it destroys any Non-key values the cookie contained. For example, if after the preceding code you call Response.Cookies with the following<br>
<br>
<% response.cookies ("MyCookie") ("newType") = "Peanut Butter"%> <br>
<br>
The value chocolate chip is discarded and NewType would are set to peanut butter.<br>
<br>
To determine whether a cookies has keys, use the following syntax.<br>
<br>
<%= response.cookies ("MyCookie"). HasKeys%> <br>
<br>
If MyCookie is a cookies dictionary, the preceding value is TRUE. Otherwise, it is false.<br>
<br>
You can use a iterator to set cookie attributes. For example, to set the cookie to expire on a particular date and use the following syntax.<br>
<br>
<% <br>
For all cookies in response.cookies<br>
Response.cookie (Cookies). ExpiresAbsolute = #July 4, 1997#<br>
Next<br>
%> <br>
<br>
You can also iterate through the "all" cookies in a collection, or all the keys in a cookie. However, if you try to iterate through of the values for a cookie this does not have keys, nothing would be returned. To avoid this, you can be the. HasKeys syntax to check whether a cookie has the any keys. This is demonstrated in the following example.<br>
<br>
<% <br>
If not cookie. HasKeys then<br>
' Set ' The value of the cookie. <br>
Response.Cookies (cookie) = "" <br>
Else<br>
' Set the ' value for each key in the cookie collection.<br>
&am



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.