SessionStateSection.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // System.Web.Configuration.SessionStateSection
  3. //
  4. // Authors:
  5. // Chris Toshok ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.ComponentModel;
  31. using System.Configuration;
  32. using System.Web.SessionState;
  33. #if NET_2_0
  34. namespace System.Web.Configuration {
  35. public sealed class SessionStateSection : ConfigurationSection
  36. {
  37. static ConfigurationProperty allowCustomSqlDatabaseProp;
  38. static ConfigurationProperty cookielessProp;
  39. static ConfigurationProperty cookieNameProp;
  40. static ConfigurationProperty customProviderProp;
  41. static ConfigurationProperty modeProp;
  42. static ConfigurationProperty partitionResolverTypeProp;
  43. static ConfigurationProperty providersProp;
  44. static ConfigurationProperty regenerateExpiredSessionIdProp;
  45. static ConfigurationProperty sessionIDManagerTypeProp;
  46. static ConfigurationProperty sqlCommandTimeoutProp;
  47. static ConfigurationProperty sqlConnectionStringProp;
  48. static ConfigurationProperty stateConnectionStringProp;
  49. static ConfigurationProperty stateNetworkTimeoutProp;
  50. static ConfigurationProperty timeoutProp;
  51. static ConfigurationProperty useHostingIdentityProp;
  52. static ConfigurationPropertyCollection properties;
  53. static SessionStateSection ()
  54. {
  55. allowCustomSqlDatabaseProp = new ConfigurationProperty ("allowCustomSqlDatabase", typeof (bool), false);
  56. cookielessProp = new ConfigurationProperty ("cookieless", typeof (HttpCookieMode));
  57. cookieNameProp = new ConfigurationProperty ("cookieName", typeof (string), "ASP.NET_SessionId");
  58. customProviderProp = new ConfigurationProperty ("customProvider", typeof (string), "");
  59. modeProp = new ConfigurationProperty ("mode", typeof (SessionStateMode), SessionStateMode.InProc);
  60. partitionResolverTypeProp = new ConfigurationProperty ("partitionResolverType", typeof (string), "");
  61. providersProp = new ConfigurationProperty ("providers", typeof (ProviderSettingsCollection));
  62. regenerateExpiredSessionIdProp = new ConfigurationProperty ("regenerateExpiredSessionId", typeof (bool), true);
  63. sessionIDManagerTypeProp = new ConfigurationProperty ("sessionIDManagerType", typeof (string), "");
  64. sqlCommandTimeoutProp = new ConfigurationProperty ("sqlCommandTimeout", typeof (TimeSpan), TimeSpan.FromSeconds (30));
  65. sqlConnectionStringProp = new ConfigurationProperty ("sqlConnectionString", typeof (string), "data source=localhost;Integrated Security=SSPI");
  66. stateConnectionStringProp = new ConfigurationProperty ("stateConnectionString", typeof (string), "tcpip=loopback:42424");
  67. stateNetworkTimeoutProp = new ConfigurationProperty ("stateNetworkTimeout", typeof (TimeSpan), TimeSpan.FromSeconds (10),
  68. PropertyHelper.TimeSpanSecondsOrInfiniteConverter,
  69. PropertyHelper.PositiveTimeSpanValidator,
  70. ConfigurationPropertyOptions.None);
  71. timeoutProp = new ConfigurationProperty ("timeout", typeof (TimeSpan), TimeSpan.FromMinutes (20),
  72. PropertyHelper.TimeSpanMinutesOrInfiniteConverter,
  73. new TimeSpanValidator (new TimeSpan (0,1,0), TimeSpan.MaxValue),
  74. ConfigurationPropertyOptions.None);
  75. useHostingIdentityProp = new ConfigurationProperty ("useHostingIdentity", typeof (bool), true);
  76. properties = new ConfigurationPropertyCollection ();
  77. properties.Add (allowCustomSqlDatabaseProp);
  78. properties.Add (cookielessProp);
  79. properties.Add (cookieNameProp);
  80. properties.Add (customProviderProp);
  81. properties.Add (modeProp);
  82. properties.Add (partitionResolverTypeProp);
  83. properties.Add (providersProp);
  84. properties.Add (regenerateExpiredSessionIdProp);
  85. properties.Add (sessionIDManagerTypeProp);
  86. properties.Add (sqlCommandTimeoutProp);
  87. properties.Add (sqlConnectionStringProp);
  88. properties.Add (stateConnectionStringProp);
  89. properties.Add (stateNetworkTimeoutProp);
  90. properties.Add (timeoutProp);
  91. properties.Add (useHostingIdentityProp);
  92. }
  93. [MonoTODO]
  94. protected override void PostDeserialize ()
  95. {
  96. base.PostDeserialize ();
  97. }
  98. [ConfigurationProperty ("allowCustomSqlDatabase", DefaultValue = "False")]
  99. public bool AllowCustomSqlDatabase {
  100. get { return (bool) base [allowCustomSqlDatabaseProp];}
  101. set { base[allowCustomSqlDatabaseProp] = value; }
  102. }
  103. [ConfigurationProperty ("cookieless")]
  104. public HttpCookieMode Cookieless {
  105. get { return (HttpCookieMode) base [cookielessProp];}
  106. set { base[cookielessProp] = value; }
  107. }
  108. [ConfigurationProperty ("cookieName", DefaultValue = "ASP.NET_SessionId")]
  109. public string CookieName {
  110. get { return (string) base [cookieNameProp];}
  111. set { base[cookieNameProp] = value; }
  112. }
  113. [ConfigurationProperty ("customProvider", DefaultValue = "")]
  114. public string CustomProvider {
  115. get { return (string) base [customProviderProp];}
  116. set { base[customProviderProp] = value; }
  117. }
  118. [ConfigurationProperty ("mode", DefaultValue = "InProc")]
  119. public SessionStateMode Mode {
  120. get { return (SessionStateMode) base [modeProp];}
  121. set { base[modeProp] = value; }
  122. }
  123. [ConfigurationProperty ("partitionResolverType", DefaultValue = "")]
  124. public string PartitionResolverType {
  125. get { return (string) base [partitionResolverTypeProp];}
  126. set { base[partitionResolverTypeProp] = value; }
  127. }
  128. [ConfigurationProperty ("providers")]
  129. public ProviderSettingsCollection Providers {
  130. get { return (ProviderSettingsCollection) base [providersProp];}
  131. }
  132. [ConfigurationProperty ("regenerateExpiredSessionId", DefaultValue = "True")]
  133. public bool RegenerateExpiredSessionId {
  134. get { return (bool) base [regenerateExpiredSessionIdProp];}
  135. set { base[regenerateExpiredSessionIdProp] = value; }
  136. }
  137. [ConfigurationProperty ("sessionIDManagerType", DefaultValue = "")]
  138. public string SessionIDManagerType {
  139. get { return (string) base [sessionIDManagerTypeProp];}
  140. set { base[sessionIDManagerTypeProp] = value; }
  141. }
  142. [TypeConverter (typeof (TimeSpanSecondsOrInfiniteConverter))]
  143. [ConfigurationProperty ("sqlCommandTimeout", DefaultValue = "00:00:30")]
  144. public TimeSpan SqlCommandTimeout {
  145. get { return (TimeSpan) base [sqlCommandTimeoutProp];}
  146. set { base[sqlCommandTimeoutProp] = value; }
  147. }
  148. [ConfigurationProperty ("sqlConnectionString", DefaultValue = "data source=localhost;Integrated Security=SSPI")]
  149. public string SqlConnectionString {
  150. get { return (string) base [sqlConnectionStringProp];}
  151. set { base[sqlConnectionStringProp] = value; }
  152. }
  153. [ConfigurationProperty ("stateConnectionString", DefaultValue = "tcpip=loopback:42424")]
  154. public string StateConnectionString {
  155. get { return (string) base [stateConnectionStringProp];}
  156. set { base[stateConnectionStringProp] = value; }
  157. }
  158. [TypeConverter (typeof (TimeSpanSecondsOrInfiniteConverter))]
  159. [ConfigurationProperty ("stateNetworkTimeout", DefaultValue = "00:00:10")]
  160. // LAMESPEC: MS lists no validator here but provides one in Properties.
  161. public TimeSpan StateNetworkTimeout {
  162. get { return (TimeSpan) base [stateNetworkTimeoutProp];}
  163. set { base[stateNetworkTimeoutProp] = value; }
  164. }
  165. [TypeConverter (typeof (TimeSpanMinutesOrInfiniteConverter))]
  166. [TimeSpanValidator (MinValueString = "00:01:00", MaxValueString = "10675199.02:48:05.4775807")]
  167. [ConfigurationProperty ("timeout", DefaultValue = "00:20:00")]
  168. public TimeSpan Timeout {
  169. get { return (TimeSpan) base [timeoutProp];}
  170. set { base[timeoutProp] = value; }
  171. }
  172. [ConfigurationProperty ("useHostingIdentity", DefaultValue = "True")]
  173. public bool UseHostingIdentity {
  174. get { return (bool) base [useHostingIdentityProp];}
  175. set { base[useHostingIdentityProp] = value; }
  176. }
  177. #if notyet
  178. [MonoTODO]
  179. public ConfigurationElementProperty ElementProperty {
  180. get { throw new NotImplementedException (); }
  181. }
  182. #endif
  183. protected override ConfigurationPropertyCollection Properties {
  184. get { return properties; }
  185. }
  186. }
  187. }
  188. #endif