2 // System.Web.SessionState.HttpSessionState
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Collections;
31 using System.Collections.Specialized;
32 using System.Globalization;
33 using System.Security.Permissions;
35 using System.Threading;
37 namespace System.Web.SessionState {
39 // CAS - no InheritanceDemand here as the class is sealed
40 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
41 public sealed class HttpSessionState : ICollection, IEnumerable
44 private SessionDictionary _dict;
45 private HttpStaticObjectsCollection _staticObjects;
47 private bool _newSession;
48 private bool _isCookieless;
49 private SessionStateMode _mode;
50 private bool _isReadonly;
51 internal bool _abandoned;
53 internal HttpSessionState (string id,
54 SessionDictionary dict,
55 HttpStaticObjectsCollection staticObjects,
59 SessionStateMode mode,
64 _staticObjects = staticObjects.Clone ();
66 _newSession = newSession;
67 _isCookieless = isCookieless;
69 _isReadonly = isReadonly;
72 internal HttpSessionState Clone ()
74 return new HttpSessionState (_id, _dict.Clone (), _staticObjects, _timeout, _newSession,
75 _isCookieless, _mode, _isReadonly);
81 HttpContext current = HttpContext.Current;
83 return Encoding.Default.CodePage;
85 return current.Response.ContentEncoding.CodePage;
89 HttpContext current = HttpContext.Current;
91 current.Response.ContentEncoding = Encoding.GetEncoding (value);
95 public HttpSessionState Contents {
100 get { return _dict.Count; }
103 internal bool IsAbandoned {
104 get { return _abandoned; }
107 public bool IsCookieless {
108 get { return _isCookieless; }
111 public bool IsNewSession {
112 get { return _newSession; }
115 public bool IsReadOnly {
116 get { return _isReadonly; }
119 public bool IsSynchronized {
120 get { return false; }
123 public object this [string key] {
124 get { return _dict [key]; }
125 set { _dict [key] = value; }
128 public object this [int index] {
129 get { return _dict [index]; }
130 set { _dict [index] = value; }
133 public NameObjectCollectionBase.KeysCollection Keys {
134 get { return _dict.Keys; }
138 get { return Thread.CurrentThread.CurrentCulture.LCID; }
139 set { Thread.CurrentThread.CurrentCulture = new CultureInfo(value); }
142 public SessionStateMode Mode {
143 get { return _mode; }
146 public string SessionID {
150 public HttpStaticObjectsCollection StaticObjects {
151 get { return _staticObjects; }
154 public object SyncRoot {
159 get { return _timeout; }
162 throw new ArgumentException ("The argument to SetTimeout must be greater than 0.");
167 internal SessionDictionary SessionDictionary {
168 get { return _dict; }
171 internal void SetNewSession (bool value)
176 public void Abandon ()
181 public void Add (string name, object value)
183 _dict [name] = value;
192 public void CopyTo (Array array, int index)
194 NameObjectCollectionBase.KeysCollection all = Keys;
195 for (int i = 0; i < all.Count; i++)
196 array.SetValue (all.Get(i), i + index);
199 public IEnumerator GetEnumerator ()
201 return _dict.GetEnumerator ();
204 public void Remove (string name)
209 public void RemoveAll ()
214 public void RemoveAt (int index)
216 _dict.RemoveAt (index);