Understanding the path and domain attributes of cookies

Source: Internet
Author: User
Tags key string in domain

Today, I found a problem during verification code execution: Windows A and B open the same page. Mr. A forms a verification code and B generates another verification code, the verification code generated by a is overwritten by B. The reason is that a cookie with the same name is used to store the verification code. If you cannot find a solution, you can refer to the webqq login screen and find that TX does not solve this problem. Maybe it is not a problem. But I 'd like to take this opportunity to learn about Cookie again.

The following is a summary after I have learned it online (please correct me if there are any mistakes ):

1. Domain indicates the domain where the cookie is located. The default value is the request address. For example, if the website address is www.test.com/test/test.aspx, then domain?www.test.com. For cross-origin access, if the Domain A is t1.test.com and the Domain B is t2.test.com, you must set the domain of the cookie to .test.com to generate a cookie that can be accessed by Domain A and Domain B in Domain; to generate a cookie in Domain A that makes Domain A inaccessible and Domain B accessible, set the domain of the cookie to t2.test.com.

2. Path indicates the directory where the cookie is located. Asp.net is/by default, which is the root directory. The directory on the same server is/test/,/test/CD/,/test/DD/, and the path of cookie1 is/test /, if the path of cookie2 is/test/CD/, all the pages under test can access cookie1, while the subpages of/test/AND/test/DD/cannot access cookie2. This is because the cookie allows the page under its path to access.

3. the browser will save cookies with the same domain and Path in one file, and use * to separate cookies.

4. Cookie with a value Key-Value Pair: Previously, the cookie with a NAM = value single key-value pair was used. Once it was said that the cookie with multiple sub-key-value pairs was lost. Now I have figured it out. The cookie format containing multiple child key-value pairs is name = key1 = value1 & key2 = value2. It can be understood that the value of a single key-Value Pair saves a custom multi-key string, where the key-Value Pair Delimiter is &, of course, you can define a separator, however, Asp.net is used as the separator.

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.