Two cookie classes in ASP. NET: httpcookie and cookie

Source: Internet
Author: User
Tags set cookie

 

System. Web. httpcookie class, corresponding to the Collection class system. Web. httpcookiecollection class

System. net. Cookie class, corresponding to the Collection class system. net. cookiecollection class

Differences:

System. Web. httpcookie is the cookie (used by the server) that the server obtains from the client through an HTTP request)

System. net. Cookie indicates the clientProgramCookie received through HTTP Response (used by the client)

Property differences:

Attribute

System. Web. httpcookie class

System. net. Cookie class (for client programs)

Constructor

Initializes a new instance of the httpcookie class.

Initialize a new instance of the cookie class according to Netscape specifications. Generally, applications do not need to construct cookie classes because they are automatically created based on the set-Cookie header received through the HTTP response.

Comment

Obtains or sets the comments that the server can add to the cookie.

Commenturi

Obtains or sets the URI comments provided by the server through cookies.

Discard

Gets or sets the discard flag set by the server

Domain

Obtains or sets the domain associated with the cookie.

Obtains or sets the valid URI of a cookie.

Expired

Get or set the cookie expiration status (true | false: expired | not expired)

Expires

Get or set the cookie expiration date and time (return datetime)

Get or set the cookie expiration date and time (datetime is returned) (minvalue by default, session cookie)

Haskeys

Whether the cookie has a subkey (get, true | false)

HTTPOnly

Specifies whether the cookie can be accessed through client scripts (get or set, true | false)

Item

Obtain the shortcut for the httpcookie. Values attribute (compatible with the old ASP version)

Name

Get or set cookie name

Get or set cookie name

Path

Obtains or sets the virtual path to be transmitted with the current cookie.

Obtains or sets the URI that the cookie applies.

Port

Obtains or sets the list of TCP ports that cookie applies.

Secure

Gets or sets a value indicating whether to use Secure Socket Layer SSL (that is, to transmit cookies only through https ).

Obtains or sets the cookie security level.

Timestamp

Obtain the time when the cookie is issued as datetime.

Value

Obtains or sets the value of a single cookie.

Obtain or set the cookie value

Values

Obtains the set of key-value pairs contained in a cookie object.

Version

Obtains or sets the HTTP status maintenance version of the cookie.

There are currently the following cookie specifications:

Draft Netscape COOKIE: the earliest cookie specification, based on rfc2109. Although this specification is significantly different from rc2109, many servers are compatible with it.

Rfc2109 is the first official cookie specification released by W3C. This specification is so strict that many servers improperly implement this specification or are still using the Netscape specification.

Rfc2965: the Specification defines cookie version 2 and describes the shortcomings of cookie version 1.

Differences:

(1) system. Web. httpcookie: initially designed for use by Web servers, because Microsoft's Web servers do not comply with rfc2109 \ rfc2965 specifications. Instead, it adopts the Netscape cookie draft scheme.

At the same time, in order to take into account some of the previous ASP encoding habits, so we have this class design.

For example, to traverse system. Web. httpcookiecollection, you can write the following code:

Foreach (string name in request. Cookies)

{

Info + = string. Format ("{0} = {1} \ r \ n", name, request. Cookies [name]. value );

}

Foreach (httpcookie cookie in request. Cookies) may encounter errors

(2) system. net. cookie class: the initial design consideration is mainly for the client. Because some server cookies follow the rfc2109 \ rfc2965 specification, the design of this class has more attributes.

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.