HttpSessionState.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. public int CodePage {
  47. get {
  48. HttpContext current = HttpContext.Current;
  49. if (current == null)
  50. return Encoding.Default.CodePage;
  51. return current.Response.ContentEncoding.CodePage;
  52. }
  53. set {
  54. HttpContext current = HttpContext.Current;
  55. if (current != null)
  56. current.Response.ContentEncoding = Encoding.GetEncoding (value);
  57. }
  58. }
  59. public HttpSessionState Contents {
  60. get { return this; }
  61. }
  62. public int Count {
  63. get { return _dict.Count; }
  64. }
  65. internal bool IsAbandoned {
  66. get { return _abandoned; }
  67. }
  68. public bool IsCookieless {
  69. get { return _isCookieless; }
  70. }
  71. public bool IsNewSession {
  72. get { return _newSession; }
  73. }
  74. public bool IsReadOnly {
  75. get { return _isReadonly; }
  76. }
  77. public bool IsSynchronized {
  78. get { return false; }
  79. }
  80. public object this [string key] {
  81. get { return _dict [key]; }
  82. set { _dict [key] = value; }
  83. }
  84. public object this [int index] {
  85. get { return _dict [index]; }
  86. set { _dict [index] = value; }
  87. }
  88. public NameObjectCollectionBase.KeysCollection Keys {
  89. get { return _dict.Keys; }
  90. }
  91. public int LCID {
  92. get { return Thread.CurrentThread.CurrentCulture.LCID; }
  93. set { Thread.CurrentThread.CurrentCulture = new CultureInfo(value); }
  94. }
  95. public SessionStateMode Mode {
  96. get { return _mode; }
  97. }
  98. public string SessionID {
  99. get { return _id; }
  100. }
  101. public HttpStaticObjectsCollection StaticObjects {
  102. get { return _staticObjects; }
  103. }
  104. public object SyncRoot {
  105. get { return this; }
  106. }
  107. public int Timeout {
  108. get { return _timeout; }
  109. set {
  110. if (value < 1)
  111. throw new ArgumentException ("The argument to SetTimeout must be greater than 0.");
  112. _timeout = value;
  113. }
  114. }
  115. internal SessionDictionary SessionDictionary {
  116. get { return _dict; }
  117. }
  118. internal void SetNewSession (bool value)
  119. {
  120. _newSession = value;
  121. }
  122. public void Abandon ()
  123. {
  124. _abandoned = true;
  125. }
  126. public void Add (string name, object value)
  127. {
  128. _dict [name] = value;
  129. }
  130. public void Clear ()
  131. {
  132. if (_dict != null)
  133. _dict.Clear ();
  134. }
  135. public void CopyTo (Array array, int index)
  136. {
  137. NameObjectCollectionBase.KeysCollection all = Keys;
  138. for (int i = 0; i < all.Count; i++)
  139. array.SetValue (all.Get(i), i + index);
  140. }
  141. public IEnumerator GetEnumerator ()
  142. {
  143. return _dict.GetEnumerator ();
  144. }
  145. public void Remove (string name)
  146. {
  147. _dict.Remove (name);
  148. }
  149. public void RemoveAll ()
  150. {
  151. _dict.Clear ();
  152. }
  153. public void RemoveAt (int index)
  154. {
  155. _dict.RemoveAt (index);
  156. }
  157. }
  158. }