2
0

HttpSessionState.cs 3.3 KB

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