Export (0) Print
Expand All

CookieCollection Class

Represents a collection of Cookie objects.

System.Object
  System.Net.CookieCollection

Namespace:  System.Net
Assembly:  System.Net (in System.Net.dll)

[DefaultMemberAttribute("Item")]
public sealed class CookieCollection : ICollection, 
	IEnumerable

The CookieCollection type exposes the following members.

  NameDescription
Public methodSupported by Silverlight for Windows PhoneCookieCollectionInitializes a new instance of the CookieCollection class.
Top

  NameDescription
Public propertySupported by Silverlight for Windows PhoneCountGets the number of cookies contained in the CookieCollection.
Public propertySupported by Silverlight for Windows PhoneIsReadOnlyGets a value that indicates whether the CookieCollection is read-only.
Public propertySupported by Silverlight for Windows PhoneIsSynchronizedGets a value that indicates whether access to the CookieCollection is thread safe.
Public propertySupported by Silverlight for Windows PhoneItemGets the cookie with the specified name from the collection.
Public propertySupported by Silverlight for Windows PhoneSyncRootGets an object that you can use to synchronize access to the CookieCollection.
Top

  NameDescription
Public methodSupported by Silverlight for Windows PhoneAdd(Cookie)Adds the specified Cookie to the collection.
Public methodSupported by Silverlight for Windows PhoneAdd(CookieCollection)Adds the contents of the specified CookieCollection to this collection.
Public methodSupported by Silverlight for Windows PhoneCopyToCopies the contents of this CookieCollection to the specified array, starting at the specified index.
Public methodSupported by Silverlight for Windows PhoneEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneGetEnumeratorGets an enumerator to iterate through the CookieCollection.
Public methodSupported by Silverlight for Windows PhoneGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public Extension MethodSupported by Silverlight for Windows PhoneAsQueryableConverts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodSupported by Silverlight for Windows PhoneCast<TResult>Converts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodSupported by Silverlight for Windows PhoneOfType<TResult>Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top

This class stores a collection of cookie objects associated with a client Web request.

You should always create a CookieCollection and add it to the request if you want to retrieve Cookie objects from the response.

The following example shows how to retrieve the CookieCollection from a response and write them to an isolated storage file.


private void ReadCallback(IAsyncResult asynchronousResult)
{
    HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
    HttpWebResponse response = (HttpWebResponse)
        request.EndGetResponse(asynchronousResult);
    using (IsolatedStorageFile isf =
        IsolatedStorageFile.GetUserStoreForSite())
    {
        using (IsolatedStorageFileStream isfs = isf.OpenFile("CookieExCookies",
            FileMode.OpenOrCreate, FileAccess.Write))
        {
            using (StreamWriter sw = new StreamWriter(isfs))
            {
                foreach (Cookie cookieValue in response.Cookies)
                {
                    sw.WriteLine("Cookie: " + cookieValue.ToString());
                }
                sw.Close();
            }
        }

    }
}


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft