2 // System.Web.HttpApplicationState
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Threading;
30 using System.Collections.Specialized;
31 using System.Security.Permissions;
33 namespace System.Web {
35 // CAS - no InheritanceDemand here as the class is sealed
36 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
37 public sealed class HttpApplicationState : NameObjectCollectionBase
\r
39 private HttpStaticObjectsCollection _AppObjects;
40 private HttpStaticObjectsCollection _SessionObjects;
42 private ReaderWriterLock _Lock;
44 internal HttpApplicationState ()
46 // do not use the public (empty) ctor as it required UnmanagedCode permission
47 _AppObjects = new HttpStaticObjectsCollection (this);
48 _SessionObjects = new HttpStaticObjectsCollection (this);
49 _Lock = new ReaderWriterLock ();
52 internal HttpApplicationState (HttpStaticObjectsCollection AppObj,
53 HttpStaticObjectsCollection SessionObj)
55 if (null != AppObj)
\r
61 // do not use the public (empty) ctor as it required UnmanagedCode permission
62 _AppObjects = new HttpStaticObjectsCollection (this);
65 if (null != SessionObj)
\r
67 _SessionObjects = SessionObj;
71 // do not use the public (empty) ctor as it required UnmanagedCode permission
72 _SessionObjects = new HttpStaticObjectsCollection (this);
74 _Lock = new ReaderWriterLock ();
77 public void Add (string name, object value)
79 _Lock.AcquireWriterLock (-1);
82 BaseAdd (name, value);
86 _Lock.ReleaseWriterLock ();
92 _Lock.AcquireWriterLock (-1);
99 _Lock.ReleaseWriterLock ();
103 public object Get (string name)
107 _Lock.AcquireReaderLock (-1);
110 ret = BaseGet (name);
114 _Lock.ReleaseReaderLock ();
120 public object Get (int index)
124 _Lock.AcquireReaderLock (-1);
127 ret = BaseGet (index);
131 _Lock.ReleaseReaderLock ();
137 public string GetKey (int index)
141 _Lock.AcquireReaderLock (-1);
144 ret = BaseGetKey (index);
148 _Lock.ReleaseReaderLock ();
156 _Lock.AcquireWriterLock (-1);
159 public void Remove (string name)
161 _Lock.AcquireWriterLock (-1);
168 _Lock.ReleaseWriterLock ();
172 public void RemoveAll ()
177 public void RemoveAt (int index)
179 _Lock.AcquireWriterLock (-1);
182 BaseRemoveAt (index);
186 _Lock.ReleaseWriterLock ();
190 public void Set (string name, object value)
192 _Lock.AcquireWriterLock (-1);
195 BaseSet (name, value);
199 _Lock.ReleaseWriterLock ();
203 public void UnLock ()
205 _Lock.ReleaseWriterLock ();
208 public string [] AllKeys
\r
212 string [] ret = null;
214 _Lock.AcquireReaderLock (-1);
217 ret = BaseGetAllKeys ();
221 _Lock.ReleaseReaderLock ();
228 public HttpApplicationState Contents
\r
233 public override int Count
\r
239 _Lock.AcquireReaderLock (-1);
246 _Lock.ReleaseReaderLock ();
253 public object this [string name]
\r
255 get { return Get (name); }
256 set { Set (name, value); }
259 public object this [int index]
\r
261 get { return Get (index); }
264 // ASP Session based objects
265 internal HttpStaticObjectsCollection SessionObjects
\r
267 get { return _SessionObjects; }
270 // ASP App based objects
271 public HttpStaticObjectsCollection StaticObjects
\r
273 get { return _AppObjects; }