2
0

HttpSessionState.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //
  2. // System.Web.SessionState.HttpSessionState
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
  8. //
  9. using System;
  10. using System.Collections;
  11. using System.Collections.Specialized;
  12. using System.Globalization;
  13. using System.Text;
  14. using System.Threading;
  15. using System.Web;
  16. namespace System.Web.SessionState {
  17. public sealed class HttpSessionState : ICollection, IEnumerable
  18. {
  19. private string _id;
  20. private SessionDictionary _dict;
  21. private HttpStaticObjectsCollection _staticObjects;
  22. private int _timeout;
  23. private bool _newSession;
  24. private bool _isCookieless;
  25. private SessionStateMode _mode;
  26. private bool _isReadonly;
  27. private bool _abandoned;
  28. internal HttpSessionState (string id,
  29. SessionDictionary dict,
  30. HttpStaticObjectsCollection staticObjects,
  31. int timeout,
  32. bool newSession,
  33. bool isCookieless,
  34. SessionStateMode mode,
  35. bool isReadonly)
  36. {
  37. _id = id;
  38. _dict = dict;
  39. _staticObjects = staticObjects;
  40. _timeout = timeout;
  41. _newSession = newSession;
  42. _isCookieless = isCookieless;
  43. _mode = mode;
  44. _isReadonly = isReadonly;
  45. }
  46. internal HttpSessionState Clone ()
  47. {
  48. return new HttpSessionState (_id, _dict.Clone (), _staticObjects, _timeout, _newSession,
  49. _isCookieless, _mode, _isReadonly);
  50. }
  51. public int CodePage {
  52. get {
  53. HttpContext current = HttpContext.Current;
  54. if (current == null)
  55. return Encoding.Default.CodePage;
  56. return current.Response.ContentEncoding.CodePage;
  57. }
  58. set {
  59. HttpContext current = HttpContext.Current;
  60. if (current != null)
  61. current.Response.ContentEncoding = Encoding.GetEncoding (value);
  62. }
  63. }
  64. public HttpSessionState Contents {
  65. get { return this; }
  66. }
  67. public int Count {
  68. get { return _dict.Count; }
  69. }
  70. internal bool IsAbandoned {
  71. get { return _abandoned; }
  72. }
  73. public bool IsCookieless {
  74. get { return _isCookieless; }
  75. }
  76. public bool IsNewSession {
  77. get { return _newSession; }
  78. }
  79. public bool IsReadOnly {
  80. get { return _isReadonly; }
  81. }
  82. public bool IsSynchronized {
  83. get { return false; }
  84. }
  85. public object this [string key] {
  86. get { return _dict [key]; }
  87. set { _dict [key] = value; }
  88. }
  89. public object this [int index] {
  90. get { return _dict [index]; }
  91. set { _dict [index] = value; }
  92. }
  93. public NameObjectCollectionBase.KeysCollection Keys {
  94. get { return _dict.Keys; }
  95. }
  96. public int LCID {
  97. get { return Thread.CurrentThread.CurrentCulture.LCID; }
  98. set { Thread.CurrentThread.CurrentCulture = new CultureInfo(value); }
  99. }
  100. public SessionStateMode Mode {
  101. get { return _mode; }
  102. }
  103. public string SessionID {
  104. get { return _id; }
  105. }
  106. public HttpStaticObjectsCollection StaticObjects {
  107. get { return _staticObjects; }
  108. }
  109. public object SyncRoot {
  110. get { return this; }
  111. }
  112. public int Timeout {
  113. get { return _timeout; }
  114. set {
  115. if (value < 1)
  116. throw new ArgumentException ("The argument to SetTimeout must be greater than 0.");
  117. _timeout = value;
  118. }
  119. }
  120. internal SessionDictionary SessionDictionary {
  121. get { return _dict; }
  122. }
  123. internal void SetNewSession (bool value)
  124. {
  125. _newSession = value;
  126. }
  127. public void Abandon ()
  128. {
  129. _abandoned = true;
  130. }
  131. public void Add (string name, object value)
  132. {
  133. _dict [name] = value;
  134. }
  135. public void Clear ()
  136. {
  137. if (_dict != null)
  138. _dict.Clear ();
  139. }
  140. public void CopyTo (Array array, int index)
  141. {
  142. NameObjectCollectionBase.KeysCollection all = Keys;
  143. for (int i = 0; i < all.Count; i++)
  144. array.SetValue (all.Get(i), i + index);
  145. }
  146. public IEnumerator GetEnumerator ()
  147. {
  148. return _dict.GetEnumerator ();
  149. }
  150. public void Remove (string name)
  151. {
  152. _dict.Remove (name);
  153. }
  154. public void RemoveAll ()
  155. {
  156. _dict.Clear ();
  157. }
  158. public void RemoveAt (int index)
  159. {
  160. _dict.RemoveAt (index);
  161. }
  162. }
  163. }