Class Cookie
Represents a cookie in the browser.
[Serializable]
public class Cookie
- Inheritance
-
Cookie
- Derived
- Inherited Members
Constructors
Cookie(string, string)
Initializes a new instance of the Cookie class with a specific name and value.
public Cookie(string name, string value)
Parameters
Exceptions
- ArgumentException
If the name is null or an empty string, or if it contains a semi-colon.
- ArgumentNullException
If the value is null.
Cookie(string, string, string)
Initializes a new instance of the Cookie class with a specific name, value, and path.
public Cookie(string name, string value, string path)
Parameters
name
stringThe name of the cookie.
value
stringThe value of the cookie.
path
stringThe path of the cookie.
Exceptions
- ArgumentException
If the name is null or an empty string, or if it contains a semi-colon.
- ArgumentNullException
If the value is null.
Cookie(string, string, string, DateTime?)
Initializes a new instance of the Cookie class with a specific name, value, path and expiration date.
public Cookie(string name, string value, string path, DateTime? expiry)
Parameters
name
stringThe name of the cookie.
value
stringThe value of the cookie.
path
stringThe path of the cookie.
expiry
DateTime?The expiration date of the cookie.
Exceptions
- ArgumentException
If the name is null or an empty string, or if it contains a semi-colon.
- ArgumentNullException
If the value is null.
Cookie(string, string, string, string, DateTime?)
Initializes a new instance of the Cookie class with a specific name, value, domain, path and expiration date.
public Cookie(string name, string value, string domain, string path, DateTime? expiry)
Parameters
name
stringThe name of the cookie.
value
stringThe value of the cookie.
domain
stringThe domain of the cookie.
path
stringThe path of the cookie.
expiry
DateTime?The expiration date of the cookie.
Exceptions
- ArgumentException
If the name is null or an empty string, or if it contains a semi-colon.
- ArgumentNullException
If the value is null.
Cookie(string, string, string, string, DateTime?, bool, bool, string)
Initializes a new instance of the ReturnedCookie class with a specific name, value, domain, path and expiration date.
public Cookie(string name, string value, string domain, string path, DateTime? expiry, bool secure, bool isHttpOnly, string sameSite)
Parameters
name
stringThe name of the cookie.
value
stringThe value of the cookie.
domain
stringThe domain of the cookie.
path
stringThe path of the cookie.
expiry
DateTime?The expiration date of the cookie.
secure
boolisHttpOnly
boolsameSite
stringThe SameSite value of cookie.
Exceptions
- ArgumentException
If the name and value are both an empty string, if the name contains a semi-colon, or if same site value is not valid.
- ArgumentNullException
If the name, value or currentUrl is null.
Properties
Domain
Gets the domain of the cookie.
[JsonPropertyName("domain")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string Domain { get; }
Property Value
Expiry
Gets the expiration date of the cookie.
[JsonIgnore]
public DateTime? Expiry { get; }
Property Value
IsHttpOnly
Gets a value indicating whether the cookie is an HTTP-only cookie.
[JsonPropertyName("httpOnly")]
public virtual bool IsHttpOnly { get; }
Property Value
Name
Gets the name of the cookie.
[JsonPropertyName("name")]
public string Name { get; }
Property Value
Path
Gets the path of the cookie.
[JsonPropertyName("path")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public virtual string Path { get; }
Property Value
SameSite
Gets the SameSite setting for the cookie.
[JsonPropertyName("sameSite")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public virtual string SameSite { get; }
Property Value
Secure
Gets a value indicating whether the cookie is secure.
[JsonPropertyName("secure")]
public virtual bool Secure { get; }
Property Value
Value
Gets the value of the cookie.
[JsonPropertyName("value")]
public string Value { get; }
Property Value
Methods
Equals(object)
public override bool Equals(object obj)
Parameters
Returns
FromDictionary(Dictionary<string, object>)
Converts a Dictionary to a Cookie.
public static Cookie FromDictionary(Dictionary<string, object> rawCookie)
Parameters
rawCookie
Dictionary<string, object>The Dictionary object containing the cookie parameters.
Returns
GetHashCode()
Serves as a hash function for a particular type.
public override int GetHashCode()
Returns
ToString()
Creates and returns a string representation of the cookie.
public override string ToString()
Returns
- string
A string representation of the cookie.