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));
111 protected override void PostDeserialize ()
113 base.PostDeserialize ();
116 [ConfigurationProperty ("allowCustomSqlDatabase", DefaultValue = "False")]
117 public bool AllowCustomSqlDatabase {
118 get { return (bool) base [allowCustomSqlDatabaseProp];}
119 set { base[allowCustomSqlDatabaseProp] = value; }
122 [ConfigurationProperty ("cookieless")]
123 public HttpCookieMode Cookieless {
124 get { return ParseCookieMode ((string) base [cookielessProp]); }
125 set { base[cookielessProp] = value.ToString(); }
128 [ConfigurationProperty ("cookieName", DefaultValue = "ASP.NET_SessionId")]
129 public string CookieName {
130 get { return (string) base [cookieNameProp];}
131 set { base[cookieNameProp] = value; }
134 [ConfigurationProperty ("customProvider", DefaultValue = "")]
135 public string CustomProvider {
136 get { return (string) base [customProviderProp];}
137 set { base[customProviderProp] = value; }
140 [ConfigurationProperty ("mode", DefaultValue = "InProc")]
141 public SessionStateMode Mode {
142 get { return (SessionStateMode) base [modeProp];}
143 set { base[modeProp] = value; }
146 [ConfigurationProperty ("partitionResolverType", DefaultValue = "")]
147 public string PartitionResolverType {
148 get { return (string) base [partitionResolverTypeProp];}
149 set { base[partitionResolverTypeProp] = value; }
152 [ConfigurationProperty ("providers")]
153 public ProviderSettingsCollection Providers {
154 get { return (ProviderSettingsCollection) base [providersProp];}
157 [ConfigurationProperty ("regenerateExpiredSessionId", DefaultValue = "True")]
158 public bool RegenerateExpiredSessionId {
159 get { return (bool) base [regenerateExpiredSessionIdProp];}
160 set { base[regenerateExpiredSessionIdProp] = value; }
163 [ConfigurationProperty ("sessionIDManagerType", DefaultValue = "")]
164 public string SessionIDManagerType {
165 get { return (string) base [sessionIDManagerTypeProp];}
166 set { base[sessionIDManagerTypeProp] = value; }
169 [TypeConverter (typeof (TimeSpanSecondsOrInfiniteConverter))]
170 [ConfigurationProperty ("sqlCommandTimeout", DefaultValue = "00:00:30")]
171 public TimeSpan SqlCommandTimeout {
172 get { return (TimeSpan) base [sqlCommandTimeoutProp];}
173 set { base[sqlCommandTimeoutProp] = value; }
176 [ConfigurationProperty ("sqlConnectionString", DefaultValue = "data source=localhost;Integrated Security=SSPI")]
177 public string SqlConnectionString {
178 get { return (string) base [sqlConnectionStringProp];}
179 set { base[sqlConnectionStringProp] = value; }
182 [ConfigurationProperty ("stateConnectionString", DefaultValue = "tcpip=loopback:42424")]
183 public string StateConnectionString {
184 get { return (string) base [stateConnectionStringProp];}
185 set { base[stateConnectionStringProp] = value; }
188 [TypeConverter (typeof (TimeSpanSecondsOrInfiniteConverter))]
189 [ConfigurationProperty ("stateNetworkTimeout", DefaultValue = "00:00:10")]
190 // LAMESPEC: MS lists no validator here but provides one in Properties.
191 public TimeSpan StateNetworkTimeout {
192 get { return (TimeSpan) base [stateNetworkTimeoutProp];}
193 set { base[stateNetworkTimeoutProp] = value; }
196 [TypeConverter (typeof (TimeSpanMinutesOrInfiniteConverter))]
197 [TimeSpanValidator (MinValueString = "00:01:00", MaxValueString = "10675199.02:48:05.4775807")]
198 [ConfigurationProperty ("timeout", DefaultValue = "00:20:00")]
199 public TimeSpan Timeout {
200 get { return (TimeSpan) base [timeoutProp];}
201 set { base[timeoutProp] = value; }
204 [ConfigurationProperty ("useHostingIdentity", DefaultValue = "True")]
205 public bool UseHostingIdentity {
206 get { return (bool) base [useHostingIdentityProp];}
207 set { base[useHostingIdentityProp] = value; }
211 static void ValidateElement (object o)
213 /* XXX do some sort of element validation here? */
216 protected override ConfigurationElementProperty ElementProperty {
217 get { return elementProperty; }
220 protected override ConfigurationPropertyCollection Properties {
221 get { return properties; }
224 HttpCookieMode ParseCookieMode (string s)
226 if (s == "true") return HttpCookieMode.UseUri;
227 else if (s == "false") 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; }