2 // System.Web.HttpCookie
5 // Patrik Torstensson (Patrik.Torstensson@labs2.com)
10 using System.Collections.Specialized;
14 public sealed class HttpCookie
24 HttpValueCollection _Values;
26 internal HttpCookie ()
31 public HttpCookie (string name)
37 public HttpCookie (string name, string value)
44 internal HttpCookie (string name, string value, string path, DateTime expires)
49 if (expires != DateTime.MinValue)
53 internal HttpResponseHeader GetCookieHeader ()
55 StringBuilder oSetCookie = new StringBuilder ();
57 if (null != _Name && _Name.Length > 0) {
58 oSetCookie.Append (_Name);
59 oSetCookie.Append ("=");
62 if (null != _Values) {
63 oSetCookie.Append (_Values.ToString (false));
64 } else if (null != _Value) {
65 oSetCookie.Append (_Value);
68 if (null != _Domain && _Domain.Length > 0) {
69 oSetCookie.Append ("; domain=");
70 oSetCookie.Append (_Domain);
73 if (null != _Path && Path.Length > 0) {
74 oSetCookie.Append ("; path=");
75 oSetCookie.Append (_Path);
78 if (_ExpiresSet && _Expires != DateTime.MinValue) {
79 oSetCookie.Append ("; expires=");
80 oSetCookie.Append (_Expires.ToUniversalTime ().ToString ("ddd, dd-MMM-yyyy HH':'mm':'ss '+0000'"));
84 oSetCookie.Append ("; secure");
86 return new HttpResponseHeader (HttpWorkerRequest.HeaderSetCookie, oSetCookie.ToString());
91 get { return _Domain; }
92 set { _Domain = value; }
95 public DateTime Expires
99 return DateTime.MinValue;
113 return Values.HasKeys ();
117 public string this [string key]
119 get { return Values [key]; }
120 set { Values [key] = value; }
125 get { return _Name; }
126 set { _Name = value; }
131 get { return _Path; }
132 set { _Path = value; }
137 get { return _Secure; }
138 set { _Secure = value; }
145 return _Values.ToString (false);
151 if (null != _Values) {
153 _Values.Add (null, value);
161 public NameValueCollection Values
164 if (null == _Values) {
165 _Values = new HttpValueCollection ();
166 if (null != _Value) {
167 // Do we have multiple keys
168 if (_Value.IndexOf ("&") >= 0 || _Value.IndexOf ("=") >= 0) {
169 _Values.FillFromCookieString (_Value);
171 _Values.Add (null, _Value);