View your cookies
You may find it helpful to understand the effect of creating a Cookie. It is easier to view cookies because they are all text files. The key is that you can find them. Different browsers store cookies in different ways. I will introduce how Internet Explorer saves cookies. If you are using another browser, please view the help of this browser to learn about Cookie processing.
An easy way to view cookies is to allow Internet Explorer to search for them. In Internet Explorer, select "Internet Options" from the "Tools" menu, click "Settings" on the "General" tab, and then click "view files ". Internet Explorer opens a window to display all temporary files, including cookies. Search for files starting with "Cookie:" or text files in the window. Double-click a Cookie to open it in the default text file.
You can also find the text file of the Cookie on the hard disk to open the Cookie. Internet Explorer saves site cookies in the file named <user >@< domain>. txt, where <user> is your account name. For example, if your name is mikepopeWww.contoso.comThe site Cookie is saved inMikepope@www.contoso.txt. (The file name may contain an sequential number, for exampleMikepope@www.contosow.1}.txt.)
This Cookie text file is related to the user, so it will be saved separately according to the account. For example, in Windows XP, you can find the Cookie file in the following directory:
C: Cookies and Settings <user> Cookies
To find the latest Cookie, you can sort the directory content by the modification date and find the most recently modified files.
You can use a text editor to open cookies. If the file contains multiple cookies, these cookies are separated by asterisks. The first line of each Cookie is the name of the Cookie, the second line is the value, and the other lines contain the daily processing information of the Cookie, such as the expiration date and time. There is also a simple checksum in the Cookie. If you change the length of the Cookie name or value, the browser will detect the modification and delete the Cookie.
Multi-value Cookie (subkey)
In the preceding example, a Cookie is used for each value (user name and last access time) to be saved. You can also save multiple name/value pairs in a Cookie. Name/value pairs are also called "keys" or "subkeys", depending on what you read. (If you are familiar with the URL structure, you will find that the subkey is very similar to the query string in it .) For example, if you do not want to create two separate cookies named "userName" and "lastVisit", you can create a Cookie named "userInfo" and make it contain two subkeys: "userName" and "lastVisit ".
There are many reasons for us to replace individual cookies with subkeys. Most obviously, it is more organized to put related or similar information in a Cookie. In addition, because all information is in one Cookie, Cookie attributes such as validity period apply to all information. (Of course, if you want to specify different expiration dates for different types of information, you should save the information in a separate Cookie .)
Cookies With subkeys can also help you reduce the Cookie size. As described in the previous section on Cookie restrictions, the total size of a Cookie is limited to 4096 bytes, and more than 20 Cookies cannot be saved for a website. Using a single Cookie with the BIND key, the number of cookies on the site will not exceed 20. In addition, a Cookie occupies a basic space overhead of about 50 characters (used to save the validity period information, etc.), plus the length of the saved value, the total number is close to 4 K. If you use five sub-keys instead of five individual cookies, you can save the basic space overhead of four cookies, saving about 200 bytes in total.
To create a Cookie with the BIND key, you can use various syntaxes used to compile a single Cookie. The following example shows two different methods for compiling the same Cookie. Each Cookie has two subkeys:
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)