[Original] spent 2 days to thoroughly understand the contents of cookies in C #, the following content will let you

Source: Internet
Author: User

[Original] spent 2 days to thoroughly understand the contents of cookies in C #, and make it clear that the following will give you a good grasp of all the cookies in your website.

Cookiecollection is a collection of all cookies for a domain
Cookecontainer is a container that can contain a collection of multiple domains of cookies, a

Cookiecontainer can contain multiple cookiecollection, which can define size and determine

The maximum number of cookies, if loaded and then installed, it will automatically remove the original expired cookies.

Again, the structure of a cookie:
Cookies are made up of variable names and values, similar to JavaScript variables. has a standard cookie in its properties

Variable, there are variables created by the user themselves, and the variables in the attribute are saved in the form "variable = value".
According to Netscape, the cookie format is as follows:

Set-cookie:name=value;expires=date;path=path;

Domain=domain_name;secure

Name=value:

This is the part that every cookie must have. Name is the cookie, and value is the

The value of the cookie. In the string "Name=value", without semicolons, commas, spaces, and so on
Character.
The expires=date:expires variable is a write-only variable that determines the valid expiration date of the cookie

Period. The attribute value date must be written in a specific format: Day of the week,
Dd-mm-yy HH:MM:SS Gmt,gmt said it was GMT. Conversely, not with such a lattice

To write, the system will not be recognized. The variable can be saved if, by default,
The property value of the cookie is not saved on the user's hard disk, but only in memory, and the cookie

The file will automatically disappear as the browser closes.
Domain=domain-name:domain the variable is a write-only variable that determines which

Web servers in the Internet domain can read cookies accessed by the browser, that is, only from this
Domain pages to use the information in cookies. This setting is optional if, by default, set

The property value of the cookie is the domain name of the Web server.
The Path=path:path property defines which pages on a Web server can get a server under which paths

The cookie that is set. Generally if a user enters a URL in the path part from the first character
Starts with the string defined by the path attribute, which the browser considers to be checked. If the Path property's

Value is "/", all WWW resources on the Web server can read the cookie. Same
This setting is optional and, if the default, the Path property value is the Web server's capital to the browser

The path name of the source.
We can see that by using the settings for domain and path two variables, we are able to effectively control

The scope of the cookie file being accessed.
Secure: Mark the variable in the cookie, indicating that the only time between the browser and the Web server

When the communication protocol is a cryptographic authentication protocol, the browser submits the corresponding
Cookies. Currently there is only one of these protocols, that is, HTTPS.
The contents of this cookie that are actually sent to the server are only name and value pairs, other things

are used to manage cookies for the client's browser, such as whether they are stored on the hard drive?

The browser will send this cookie when visiting the website.

These types of conversion methods:
Cookiecontainer.getcookies () Get cookiecollection, while cookiecollection straight

Add an index number to obtain a specific cookie,

Cookiecontainer.add () can add cookies or cookiecollection, even directly with

The cookie information in the HTTP header can be added directly to the Cookiecontainer, using the

Cookiecontainer.setcookies (Uri, String) is implemented, where string is the string content of the cookie, which can be passed through the response. Headers.get ("Set-cookie"), notice here that the Uri in the setcookies () function cannot be exactly the same as the domain name in the Cookie string, such as the Uri=new uri ("http://."). Google.com "), while cookies in the

Domain=.google.com, this time the cookiecontainer.setcookies () function will have an error,

Prompt domain name is incorrect, the workaround is, Uri = new Uri ("http://www.google.com") can,

Anyway, change to other similar paths can, why not the same, who knows, ask Microsoft to go. That's it.

The problem of the place, I spent a few hours.

The Cookiecontainer.getcookieheader () function can read all the points in the Cookiecontainer

The cookie for the Web site is displayed as a string.
You want to enter a string to construct the cookie individually, and it's simple, the cookie constructor is done.

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.