2 using System.Collections.Generic;
15 public string Key {
get;
private set; }
19 public string Value {
get;
private set; }
23 public Dictionary<string, string>
Attributes {
get;
private set; }
29 public Cookie(
string key,
string value)
42 string[] cookieTokens = cookieString.Split(
';');
43 Key = cookieTokens[0].Split(
'=')[0].Trim();
44 Value = cookieTokens[1].Split(
'=')[1].Trim();
45 for(
int i = 1; i < cookieTokens.Length; i++)
47 string[] attributeTokens = cookieTokens[i].Split(
'=');
48 Attributes[attributeTokens[0].Trim()] = attributeTokens.Length > 1 ? attributeTokens[1].Trim() :
string.Empty;
57 StringBuilder sb =
new StringBuilder();
58 sb.Append(
Key).Append(
'=').Append(
Value);
61 foreach(KeyValuePair<string, string> attribute
in Attributes)
63 sb.Append(
';').Append(attribute.Key);
64 if (!
string.IsNullOrWhiteSpace(attribute.Value))
66 sb.Append(
'=').Append(attribute.Value);
Cookie(string cookieString)
Creates a new instance of cookie class.
Dictionary< string, string > Attributes
Dictionary containing cookie attributes.
string BuildCookieString()
Build the string containing the cookie definition.
byte [] BuildCookieBytes()
Build the byte array containing the cookie definition.
string Value
Value of cookie.
Cookie(string key, string value)
Creates a new instance of cookie class.