Access and update Cookies
The value of Cookies is much more complex than that of other sets of ASP (such as Form and ServerVariables. Cookie is a small piece of text stored by the browser on the client system, and each request is sent to the server in the domain they are applied.
ASP makes the application cookie easier. You can obtain all the cookie values sent along with the Request from the cookie set of the Request object, and create or modify the cookie, send it back to the user through the cookie set of the Response object.
Cookie contains information constructed in two ways. A single-value cookie provides its value to the code through a common ASP-like set. However, each member of a set may also be a set. Cookies containing such information are called multiple-Value cookies.
Creating a single-value cookie is simple, as shown below:
Response. Cookies ("item-name") = "item-value"
To create a multi-value cookie, run the following command:
Response. Cookies ("item-name") ("sub-item-name") = "sub-item-value"
Set the domain and path of the cookie application and its validity period. We use:
Response. Cookies ("item-name"). domain = "domain-url"
Response. Cookies ("item-name"). path = "virtual-path"
Response. Cookies ("item-name"). expires = # date #
Generally, the customer sends the cookie request to the server only when making a request to the page in the cookie creation directory. By specifying the path attribute, you can specify where the cookie is valid on the site, and the cookie will be sent with the request. If the cookie is sent along with the page request to the entire site, set path to "/".
If the Expires attribute is not set, the cookie is automatically cleared when the current browser instance is closed.
Note that a cookie has been created when we send any output to the browser. Because these cookies are part of the HTTP header of the page.
In ASP 3.0, the buffer is enabled by default, and no output is sent, unless Response. Flush is used to define this job or the page is reached the end. This means that the cookie creation code can be executed at any location on the page until any "refresh" (flush) is output to the client.
To read existing Cookies, use the Request. Cookies set. You can access the projects in them by using methods similar to those used when creating them.
StrSingleValue = Request. Cookies ("item-name ")
StrSubItemValue = Request. Cookies ("item-name") ("sub-item-name ")
Note that the Request. Cookies set (the same as all other Request sets) is read-only. Response. The cookie set is only written. In fact, you can access the names of a series of Cookies in this set, rather than their values.
Traverse Cookies
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.