HttpSessionState.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 { _timeout = value; }
  110. }
  111. public void Abandon ()
  112. {
  113. _abandoned = true;
  114. }
  115. public void Add (string name, object value)
  116. {
  117. _dict [name] = value;
  118. }
  119. public void Clear ()
  120. {
  121. if (_dict != null)
  122. _dict.Clear ();
  123. }
  124. public void CopyTo (Array array, int index)
  125. {
  126. NameObjectCollectionBase.KeysCollection all = Keys;
  127. for (int i = 0; i < all.Count; i++)
  128. array.SetValue (_dict [all [i]], i + index);
  129. }
  130. public IEnumerator GetEnumerator ()
  131. {
  132. return _dict.GetEnumerator ();
  133. }
  134. public void Remove (string name)
  135. {
  136. _dict.Remove (name);
  137. }
  138. public void RemoveAll ()
  139. {
  140. _dict.Clear ();
  141. }
  142. public void RemoveAt (int index)
  143. {
  144. _dict.RemoveAt (index);
  145. }
  146. }
  147. }