* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Web / System.Web.SessionState / HttpSessionState.cs
index f78fa4717f7e4366c935399d2aa1f8e2b6a2883c..2867059771811c03417817df0366752c441acd66 100644 (file)
@@ -5,16 +5,39 @@
 //     Gonzalo Paniagua Javier (gonzalo@ximian.com)
 //
 // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
 //
-using System;
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System.Collections;
 using System.Collections.Specialized;
 using System.Globalization;
+using System.Security.Permissions;
 using System.Text;
 using System.Threading;
-using System.Web;
 
 namespace System.Web.SessionState {
+
+// CAS - no InheritanceDemand here as the class is sealed
+[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
 public sealed class HttpSessionState : ICollection, IEnumerable
 {
        private string _id;
@@ -25,7 +48,7 @@ public sealed class HttpSessionState : ICollection, IEnumerable
        private bool _isCookieless;
        private SessionStateMode _mode;
        private bool _isReadonly;
-       private bool _abandoned;
+       internal bool _abandoned;
 
        internal HttpSessionState (string id,
                                   SessionDictionary dict,
@@ -38,7 +61,7 @@ public sealed class HttpSessionState : ICollection, IEnumerable
        {
                _id = id;
                _dict = dict;
-               _staticObjects = staticObjects;
+               _staticObjects = staticObjects.Clone ();
                _timeout = timeout;
                _newSession = newSession;
                _isCookieless = isCookieless;
@@ -46,6 +69,13 @@ public sealed class HttpSessionState : ICollection, IEnumerable
                _isReadonly = isReadonly;
        }
 
+       internal HttpSessionState Clone ()
+       {
+               return new HttpSessionState (_id, _dict.Clone (), _staticObjects, _timeout, _newSession,
+                                            _isCookieless, _mode, _isReadonly);
+
+       }
+
        public int CodePage {
                get {
                        HttpContext current = HttpContext.Current;
@@ -127,7 +157,20 @@ public sealed class HttpSessionState : ICollection, IEnumerable
 
        public int Timeout {
                get { return _timeout; }
-               set { _timeout = value; }
+               set {
+                        if (value < 1)
+                                throw new ArgumentException ("The argument to SetTimeout must be greater than 0.");
+                        _timeout = value;
+                }
+       }
+
+       internal SessionDictionary SessionDictionary {
+               get { return _dict; }
+       }
+
+       internal void SetNewSession (bool value)
+       {
+               _newSession = value;
        }
 
        public void Abandon ()
@@ -150,7 +193,7 @@ public sealed class HttpSessionState : ICollection, IEnumerable
        {
                NameObjectCollectionBase.KeysCollection all = Keys;
                for (int i = 0; i < all.Count; i++)
-                       array.SetValue (_dict [all [i]], i + index);
+                       array.SetValue (all.Get(i), i + index);
        }
 
        public IEnumerator GetEnumerator ()