CookieHeaderParser Class
Represents a parser for the 'Cookie' header.
- Namespace:
- System.Net.Http.Headers
- Assembly:
- System.Net.Http.dll
Inheritance
- object
- CookieHeaderParser
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:
-
stringvalue: The cookie header string to parse.
- Returns:
- A CookieHeaderValue object representing the parsed cookie header.
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:
-
stringvalue: The cookie header string to parse. -
out CookieHeaderValueresult: When this method returns, contains the parsed CookieHeaderValue, if parsing succeeded, ornullif parsing failed.
- Returns:
trueif the cookie header was parsed successfully; otherwise,false.
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.");
}