2 // System.Web.Configuration.SessionStateSection
5 // Chris Toshok (toshok@ximian.com)
7 // (C) 2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.ComponentModel;
33 using System.Configuration;
34 using System.Web.SessionState;
38 namespace System.Web.Configuration {
40 public sealed class SessionStateSection : ConfigurationSection
42 static ConfigurationProperty allowCustomSqlDatabaseProp;
43 static ConfigurationProperty cookielessProp;
44 static ConfigurationProperty cookieNameProp;
45 static ConfigurationProperty customProviderProp;
46 static ConfigurationProperty modeProp;
47 static ConfigurationProperty partitionResolverTypeProp;
48 static ConfigurationProperty providersProp;
49 static ConfigurationProperty regenerateExpiredSessionIdProp;
50 static ConfigurationProperty sessionIDManagerTypeProp;
51 static ConfigurationProperty sqlCommandTimeoutProp;
52 static ConfigurationProperty sqlConnectionStringProp;
53 static ConfigurationProperty stateConnectionStringProp;
54 static ConfigurationProperty stateNetworkTimeoutProp;
55 static ConfigurationProperty timeoutProp;
56 static ConfigurationProperty useHostingIdentityProp;
57 static ConfigurationPropertyCollection properties;
59 static ConfigurationElementProperty elementProperty;
61 static SessionStateSection ()
63 allowCustomSqlDatabaseProp = new ConfigurationProperty ("allowCustomSqlDatabase", typeof (bool), false);
64 cookielessProp = new ConfigurationProperty ("cookieless", typeof (string), null);
65 cookieNameProp = new ConfigurationProperty ("cookieName", typeof (string), "ASP.NET_SessionId");
66 customProviderProp = new ConfigurationProperty ("customProvider", typeof (string), "");
67 modeProp = new ConfigurationProperty ("mode", typeof (SessionStateMode), SessionStateMode.InProc,
68 new GenericEnumConverter (typeof (SessionStateMode)), null,
69 ConfigurationPropertyOptions.None);
70 partitionResolverTypeProp = new ConfigurationProperty ("partitionResolverType", typeof (string), "");
71 providersProp = new ConfigurationProperty ("providers", typeof (ProviderSettingsCollection), null,
72 null, null, ConfigurationPropertyOptions.None);
73 regenerateExpiredSessionIdProp = new ConfigurationProperty ("regenerateExpiredSessionId", typeof (bool), true);
74 sessionIDManagerTypeProp = new ConfigurationProperty ("sessionIDManagerType", typeof (string), "");
75 sqlCommandTimeoutProp = new ConfigurationProperty ("sqlCommandTimeout", typeof (TimeSpan), TimeSpan.FromSeconds (30),
76 PropertyHelper.TimeSpanSecondsOrInfiniteConverter, null,
77 ConfigurationPropertyOptions.None);
78 sqlConnectionStringProp = new ConfigurationProperty ("sqlConnectionString", typeof (string), "data source=localhost;Integrated Security=SSPI");
79 stateConnectionStringProp = new ConfigurationProperty ("stateConnectionString", typeof (string), "tcpip=loopback:42424");
80 stateNetworkTimeoutProp = new ConfigurationProperty ("stateNetworkTimeout", typeof (TimeSpan), TimeSpan.FromSeconds (10),
81 PropertyHelper.TimeSpanSecondsOrInfiniteConverter,
82 PropertyHelper.PositiveTimeSpanValidator,
83 ConfigurationPropertyOptions.None);
84 timeoutProp = new ConfigurationProperty ("timeout", typeof (TimeSpan), TimeSpan.FromMinutes (20),
85 PropertyHelper.TimeSpanMinutesOrInfiniteConverter,
86 new TimeSpanValidator (new TimeSpan (0,1,0), TimeSpan.MaxValue),
87 ConfigurationPropertyOptions.None);
88 useHostingIdentityProp = new ConfigurationProperty ("useHostingIdentity", typeof (bool), true);
89 properties = new ConfigurationPropertyCollection ();
91 properties.Add (allowCustomSqlDatabaseProp);
92 properties.Add (cookielessProp);
93 properties.Add (cookieNameProp);
94 properties.Add (customProviderProp);
95 properties.Add (modeProp);
96 properties.Add (partitionResolverTypeProp);
97 properties.Add (providersProp);
98 properties.Add (regenerateExpiredSessionIdProp);
99 properties.Add (sessionIDManagerTypeProp);
100 properties.Add (sqlCommandTimeoutProp);
101 properties.Add (sqlConnectionStringProp);
102 properties.Add (stateConnectionStringProp);
103 properties.Add (stateNetworkTimeoutProp);
104 properties.Add (timeoutProp);
105 properties.Add (useHostingIdentityProp);
107 elementProperty = new ConfigurationElementProperty (new CallbackValidator (typeof (SessionStateSection), ValidateElement));
110 protected override void PostDeserialize ()
112 base.PostDeserialize ();
115 [ConfigurationProperty ("allowCustomSqlDatabase", DefaultValue = "False")]
116 public bool AllowCustomSqlDatabase {
117 get { return (bool) base [allowCustomSqlDatabaseProp];}
118 set { base[allowCustomSqlDatabaseProp] = value; }
121 [ConfigurationProperty ("cookieless")]
122 public HttpCookieMode Cookieless {
123 get { return ParseCookieMode ((string) base [cookielessProp]); }
124 set { base[cookielessProp] = value.ToString(); }
127 [ConfigurationProperty ("cookieName", DefaultValue = "ASP.NET_SessionId")]
128 public string CookieName {
129 get { return (string) base [cookieNameProp];}
130 set { base[cookieNameProp] = value; }
133 [ConfigurationProperty ("customProvider", DefaultValue = "")]
134 public string CustomProvider {
135 get { return (string) base [customProviderProp];}
136 set { base[customProviderProp] = value; }
139 [ConfigurationProperty ("mode", DefaultValue = "InProc")]
140 public SessionStateMode Mode {
141 get { return (SessionStateMode) base [modeProp];}
142 set { base[modeProp] = value; }
145 [ConfigurationProperty ("partitionResolverType", DefaultValue = "")]
146 public string PartitionResolverType {
147 get { return (string) base [partitionResolverTypeProp];}
148 set { base[partitionResolverTypeProp] = value; }
151 [ConfigurationProperty ("providers")]
152 public ProviderSettingsCollection Providers {
153 get { return (ProviderSettingsCollection) base [providersProp];}
156 [ConfigurationProperty ("regenerateExpiredSessionId", DefaultValue = "True")]
157 public bool RegenerateExpiredSessionId {
158 get { return (bool) base [regenerateExpiredSessionIdProp];}
159 set { base[regenerateExpiredSessionIdProp] = value; }
162 [ConfigurationProperty ("sessionIDManagerType", DefaultValue = "")]
163 public string SessionIDManagerType {
164 get { return (string) base [sessionIDManagerTypeProp];}
165 set { base[sessionIDManagerTypeProp] = value; }
168 [TypeConverter (typeof (TimeSpanSecondsOrInfiniteConverter))]
169 [ConfigurationProperty ("sqlCommandTimeout", DefaultValue = "00:00:30")]
170 public TimeSpan SqlCommandTimeout {
171 get { return (TimeSpan) base [sqlCommandTimeoutProp];}
172 set { base[sqlCommandTimeoutProp] = value; }
175 [ConfigurationProperty ("sqlConnectionString", DefaultValue = "data source=localhost;Integrated Security=SSPI")]
176 public string SqlConnectionString {
177 get { return (string) base [sqlConnectionStringProp];}
178 set { base[sqlConnectionStringProp] = value; }
181 [ConfigurationProperty ("stateConnectionString", DefaultValue = "tcpip=loopback:42424")]
182 public string StateConnectionString {
183 get { return (string) base [stateConnectionStringProp];}
184 set { base[stateConnectionStringProp] = value; }
187 [TypeConverter (typeof (TimeSpanSecondsOrInfiniteConverter))]
188 [ConfigurationProperty ("stateNetworkTimeout", DefaultValue = "00:00:10")]
189 // LAMESPEC: MS lists no validator here but provides one in Properties.
190 public TimeSpan StateNetworkTimeout {
191 get { return (TimeSpan) base [stateNetworkTimeoutProp];}
192 set { base[stateNetworkTimeoutProp] = value; }
195 [TypeConverter (typeof (TimeSpanMinutesOrInfiniteConverter))]
196 [TimeSpanValidator (MinValueString = "00:01:00", MaxValueString = "10675199.02:48:05.4775807")]
197 [ConfigurationProperty ("timeout", DefaultValue = "00:20:00")]
198 public TimeSpan Timeout {
199 get { return (TimeSpan) base [timeoutProp];}
200 set { base[timeoutProp] = value; }
203 [ConfigurationProperty ("useHostingIdentity", DefaultValue = "True")]
204 public bool UseHostingIdentity {
205 get { return (bool) base [useHostingIdentityProp];}
206 set { base[useHostingIdentityProp] = value; }
209 static void ValidateElement (object o)
211 /* XXX do some sort of element validation here? */
214 protected override ConfigurationElementProperty ElementProperty {
215 get { return elementProperty; }
218 protected override ConfigurationPropertyCollection Properties {
219 get { return properties; }
222 HttpCookieMode ParseCookieMode (string s)
225 return HttpCookieMode.UseUri;
226 else if (s == "false" || s == null)
227 return HttpCookieMode.UseCookies;
230 return (HttpCookieMode)Enum.Parse (typeof(HttpCookieMode), s);
233 return HttpCookieMode.UseCookies;
238 #region CompatabilityCode
239 internal bool CookieLess {
240 get { return Cookieless != HttpCookieMode.UseCookies; }
241 set { Cookieless = value ? HttpCookieMode.UseUri : HttpCookieMode.UseCookies; }