CookieHeaderParser Class

Represents a parser for the 'Cookie' header.
Namespace:
System.Net.Http.Headers
Assembly:
System.Net.Http.dll

Inheritance

Constructors

Public Constructors

public CookieHeaderParser()
Initializes a new instance of the CookieHeaderParser class.

Methods

Public Methods

public static CookieHeaderValue ParseCookieHeader(string value)
Parses a cookie header string.
Parameters:
string value: The cookie header string to parse.
Returns:
A CookieHeaderValue object representing the parsed cookie header.
Show example usage

using System.Net.Http.Headers;

string cookieString = "sessionid=abc123; expires=Wed, 21 Oct 2015 07:28:00 GMT";
CookieHeaderValue cookieHeader = CookieHeaderParser.ParseCookieHeader(cookieString);

Console.WriteLine($"Session ID: {cookieHeader.ToString()}");
// Output: Session ID: sessionid=abc123
                    
public static bool TryParseCookieHeader(string value, out CookieHeaderValue result)
Tries to parse a cookie header string.
Parameters:
string value: The cookie header string to parse.
out CookieHeaderValue result: When this method returns, contains the parsed CookieHeaderValue, if parsing succeeded, or null if parsing failed.
Returns:
true if the cookie header was parsed successfully; otherwise, false.
Show example usage

using System.Net.Http.Headers;

string cookieString = "sessionid=abc123; expires=Wed, 21 Oct 2015 07:28:00 GMT";
CookieHeaderValue parsedCookie;

if (CookieHeaderParser.TryParseCookieHeader(cookieString, out parsedCookie))
{
    Console.WriteLine($"Successfully parsed cookie: {parsedCookie.ToString()}");
}
else
{
    Console.WriteLine("Failed to parse cookie.");
}