2 // System.Web.SessionState.HttpSessionState
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
32 using System.Collections.Specialized;
33 using System.Globalization;
35 using System.Threading;
38 namespace System.Web.SessionState {
39 public sealed class HttpSessionState : ICollection, IEnumerable
42 private SessionDictionary _dict;
43 private HttpStaticObjectsCollection _staticObjects;
45 private bool _newSession;
46 private bool _isCookieless;
47 private SessionStateMode _mode;
48 private bool _isReadonly;
49 internal bool _abandoned;
51 internal HttpSessionState (string id,
52 SessionDictionary dict,
53 HttpStaticObjectsCollection staticObjects,
57 SessionStateMode mode,
62 _staticObjects = staticObjects.Clone ();
64 _newSession = newSession;
65 _isCookieless = isCookieless;
67 _isReadonly = isReadonly;
70 internal HttpSessionState Clone ()
72 return new HttpSessionState (_id, _dict.Clone (), _staticObjects, _timeout, _newSession,
73 _isCookieless, _mode, _isReadonly);
79 HttpContext current = HttpContext.Current;
81 return Encoding.Default.CodePage;
83 return current.Response.ContentEncoding.CodePage;
87 HttpContext current = HttpContext.Current;
89 current.Response.ContentEncoding = Encoding.GetEncoding (value);
93 public HttpSessionState Contents {
98 get { return _dict.Count; }
101 internal bool IsAbandoned {
102 get { return _abandoned; }
105 public bool IsCookieless {
106 get { return _isCookieless; }
109 public bool IsNewSession {
110 get { return _newSession; }
113 public bool IsReadOnly {
114 get { return _isReadonly; }
117 public bool IsSynchronized {
118 get { return false; }
121 public object this [string key] {
122 get { return _dict [key]; }
123 set { _dict [key] = value; }
126 public object this [int index] {
127 get { return _dict [index]; }
128 set { _dict [index] = value; }
131 public NameObjectCollectionBase.KeysCollection Keys {
132 get { return _dict.Keys; }
136 get { return Thread.CurrentThread.CurrentCulture.LCID; }
137 set { Thread.CurrentThread.CurrentCulture = new CultureInfo(value); }
140 public SessionStateMode Mode {
141 get { return _mode; }
144 public string SessionID {
148 public HttpStaticObjectsCollection StaticObjects {
149 get { return _staticObjects; }
152 public object SyncRoot {
157 get { return _timeout; }
160 throw new ArgumentException ("The argument to SetTimeout must be greater than 0.");
165 internal SessionDictionary SessionDictionary {
166 get { return _dict; }
169 internal void SetNewSession (bool value)
174 public void Abandon ()
179 public void Add (string name, object value)
181 _dict [name] = value;
190 public void CopyTo (Array array, int index)
192 NameObjectCollectionBase.KeysCollection all = Keys;
193 for (int i = 0; i < all.Count; i++)
194 array.SetValue (all.Get(i), i + index);
197 public IEnumerator GetEnumerator ()
199 return _dict.GetEnumerator ();
202 public void Remove (string name)
207 public void RemoveAll ()
212 public void RemoveAt (int index)
214 _dict.RemoveAt (index);