What is Cookie?
Cookie is associated with a Web site rather than a specific page. Therefore, no matter which page the user requests to visit the site, the browser and server will exchange Cookie information of www.contoso.com. When a user accesses other sites, each site may send a Cookie to the user's browser, and the browser will save all these cookies separately.
Cookie restrictions
Before discussing the technical details of cookies, I would like to introduce several restrictions on Cookie applications. Most browsers support up to 4096 bytes of cookies. If you want to save a few values to your computer, this space is large enough, however, you cannot use a Cookie to save a dataset or a large amount of other data. In practice, you may not want to save a large amount of user information in cookies, but only want to save user numbers or other identifiers. Then, when the user visits your site again, you can use this user ID to search for the user's details in the database.
Compile Cookie
Response. Cookies ("userName"). Value = "mike"
Response. Cookies ("userName"). Expires = DateTime. Now. AddDays (1)
Dim aCookie As New HttpCookie ("lastVisit ")
ACookie. Value = DateTime. Now. ToString
ACookie. Expires = DateTime. Now. AddDays (1)
Response. Cookies. Add (aCookie)
Multi-value Cookie (subkey)
Response. Cookies ("userInfo") ("userName") = "mike"
Response. Cookies ("userInfo") ("lastVisit") = DateTime. Now. ToString
Response. Cookies ("userInfo"). Expires = DateTime. Now. AddDays (1)
Dim aCookie As New HttpCookie ("userInfo ")
ACookie. Values ("userName") = "mike"
ACookie. Values ("lastVisit") = DateTime. Now. ToString
ACookie. Expires = DateTime. Now. AddDays (1)
Response. Cookies. Add (aCookie)
Modify or delete a subkey
Dim subkeyName As String
SubkeyName = "userName"
Dim aCookie As HttpCookie = Request. Cookies ("userInfo ")
ACookie. Values. Remove (subkeyName)
ACookie. Expires = DateTime. Now. AddDays (1)
Response. Cookies. Add (aCookie)
(Set the expiration time of cook, otherwise it will be destroyed at the end of the page)
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