HttpSessionState.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. set { _newSession=value; }
  74. }
  75. public bool IsReadOnly {
  76. get { return _isReadonly; }
  77. }
  78. public bool IsSynchronized {
  79. get { return false; }
  80. }
  81. public object this [string key] {
  82. get { return _dict [key]; }
  83. set { _dict [key] = value; }
  84. }
  85. public object this [int index] {
  86. get { return _dict [index]; }
  87. set { _dict [index] = value; }
  88. }
  89. public NameObjectCollectionBase.KeysCollection Keys {
  90. get { return _dict.Keys; }
  91. }
  92. public int LCID {
  93. get { return Thread.CurrentThread.CurrentCulture.LCID; }
  94. set { Thread.CurrentThread.CurrentCulture = new CultureInfo(value); }
  95. }
  96. public SessionStateMode Mode {
  97. get { return _mode; }
  98. }
  99. public string SessionID {
  100. get { return _id; }
  101. }
  102. public HttpStaticObjectsCollection StaticObjects {
  103. get { return _staticObjects; }
  104. }
  105. public object SyncRoot {
  106. get { return this; }
  107. }
  108. public int Timeout {
  109. get { return _timeout; }
  110. set {
  111. if (value < 1)
  112. throw new ArgumentException ("The argument to SetTimeout must be greater than 0.");
  113. _timeout = value;
  114. }
  115. }
  116. internal SessionDictionary SessionDictionary {
  117. get { return _dict; }
  118. }
  119. public void Abandon ()
  120. {
  121. _abandoned = true;
  122. }
  123. public void Add (string name, object value)
  124. {
  125. _dict [name] = value;
  126. }
  127. public void Clear ()
  128. {
  129. if (_dict != null)
  130. _dict.Clear ();
  131. }
  132. public void CopyTo (Array array, int index)
  133. {
  134. NameObjectCollectionBase.KeysCollection all = Keys;
  135. for (int i = 0; i < all.Count; i++)
  136. array.SetValue (all.Get(i), i + index);
  137. }
  138. public IEnumerator GetEnumerator ()
  139. {
  140. return _dict.GetEnumerator ();
  141. }
  142. public void Remove (string name)
  143. {
  144. _dict.Remove (name);
  145. }
  146. public void RemoveAll ()
  147. {
  148. _dict.Clear ();
  149. }
  150. public void RemoveAt (int index)
  151. {
  152. _dict.RemoveAt (index);
  153. }
  154. }
  155. }