Cookie in C#

[Cookie Class]

Provides a set of properties and methods that are used to manage cookies. This class cannot be inherited.

 

下面是msdn中的代码示例:

 

            // Print the properties of each cookie.
            foreach (Cookie cook in response.Cookies)
            {
                Console.WriteLine("Cookie:");
                Console.WriteLine("{0} = {1}", cook.Name, cook.Value);
                Console.WriteLine("Domain: {0}", cook.Domain);
                Console.WriteLine("Path: {0}", cook.Path);
                Console.WriteLine("Port: {0}", cook.Port);
                Console.WriteLine("Secure: {0}", cook.Secure);

                Console.WriteLine("When issued: {0}", cook.TimeStamp);
                Console.WriteLine("Expires: {0} (expired? {1})",
                    cook.Expires, cook.Expired);
                Console.WriteLine("Don't save: {0}", cook.Discard);
                Console.WriteLine("Comment: {0}", cook.Comment);
                Console.WriteLine("Uri for comments: {0}", cook.CommentUri);
                Console.WriteLine("Version: RFC {0}", cook.Version == 1 ? "2109" : "2965");

                // Show the string representation of the cookie.
                Console.WriteLine("String: {0}", cook.ToString());
            }

[CookieCollection Class]

Provides a collection container for instances of the Cookie class.

 

输出collection container中的cookie可能会用到如下方法:

 

GetEnumeratorGets an enumerator that can iterate through a CookieCollection .
ToStringReturns a String that represents the current Object. (Inherited from Object.)

 

[CookieContainer Class]

 

A CookieContainer is a data structure that provides storage for instances of the Cookie class, and which is accessed in a database-like manner. The CookieContainer has a capacity limit that is set when the container is created or changed by a property.


An instance of the Cookie class is added to the container based on its originating URI. It is added to an internal CookieCollection associated with the URI. A Cookie is retrieved from the container based on the URI as a CookieCollection, or as a string that can be used to submit HTTP WebRequests.


The CookieContainer has three properties that govern the volume of the content of the container: Capacity, MaxCookieSize, and PerDomainCapacity. These values have the default settings of 300, 4096, and 20 respectively. When a Cookie is added to the container, these properties are used to determine whether a Cookie already contained in the CookieContainer should be discarded to make room for the new one. The CookieContainer keeps track of each addition to ensure that neither the Capacity nor the PerDomainCapacity limits are exceeded. If one or both are exceeded, then Cookie instances held by the CookieContainer are removed. First, any expired Cookie is removed. If further capacity must be recaptured, then the least-recently used CookieCollection is purged. - From MSDN

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值