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 partitionResolverTypeProp = new ConfigurationProperty ("partitionResolverType", typeof (string), "");
69 providersProp = new ConfigurationProperty ("providers", typeof (ProviderSettingsCollection));
70 regenerateExpiredSessionIdProp = new ConfigurationProperty ("regenerateExpiredSessionId", typeof (bool), true);
71 sessionIDManagerTypeProp = new ConfigurationProperty ("sessionIDManagerType", typeof (string), "");
72 sqlCommandTimeoutProp = new ConfigurationProperty ("sqlCommandTimeout", typeof (TimeSpan), TimeSpan.FromSeconds (30));
73 sqlConnectionStringProp = new ConfigurationProperty ("sqlConnectionString", typeof (string), "data source=localhost;Integrated Security=SSPI");
74 stateConnectionStringProp = new ConfigurationProperty ("stateConnectionString", typeof (string), "tcpip=loopback:42424");
75 stateNetworkTimeoutProp = new ConfigurationProperty ("stateNetworkTimeout", typeof (TimeSpan), TimeSpan.FromSeconds (10),
76 PropertyHelper.TimeSpanSecondsOrInfiniteConverter,
77 PropertyHelper.PositiveTimeSpanValidator,
78 ConfigurationPropertyOptions.None);
79 timeoutProp = new ConfigurationProperty ("timeout", typeof (TimeSpan), TimeSpan.FromMinutes (20),
80 PropertyHelper.TimeSpanMinutesOrInfiniteConverter,
81 new TimeSpanValidator (new TimeSpan (0,1,0), TimeSpan.MaxValue),
82 ConfigurationPropertyOptions.None);
83 useHostingIdentityProp = new ConfigurationProperty ("useHostingIdentity", typeof (bool), true);
84 properties = new ConfigurationPropertyCollection ();
86 properties.Add (allowCustomSqlDatabaseProp);
87 properties.Add (cookielessProp);
88 properties.Add (cookieNameProp);
89 properties.Add (customProviderProp);
90 properties.Add (modeProp);
91 properties.Add (partitionResolverTypeProp);
92 properties.Add (providersProp);
93 properties.Add (regenerateExpiredSessionIdProp);
94 properties.Add (sessionIDManagerTypeProp);
95 properties.Add (sqlCommandTimeoutProp);
96 properties.Add (sqlConnectionStringProp);
97 properties.Add (stateConnectionStringProp);
98 properties.Add (stateNetworkTimeoutProp);
99 properties.Add (timeoutProp);
100 properties.Add (useHostingIdentityProp);
102 elementProperty = new ConfigurationElementProperty (new CallbackValidator (typeof (SessionStateSection), ValidateElement));
106 protected override void PostDeserialize ()
108 base.PostDeserialize ();
111 [ConfigurationProperty ("allowCustomSqlDatabase", DefaultValue = "False")]
112 public bool AllowCustomSqlDatabase {
113 get { return (bool) base [allowCustomSqlDatabaseProp];}
114 set { base[allowCustomSqlDatabaseProp] = value; }
117 [ConfigurationProperty ("cookieless")]
118 public HttpCookieMode Cookieless {
119 get { return ParseCookieMode ((string) base [cookielessProp]); }
120 set { base[cookielessProp] = value.ToString(); }
123 [ConfigurationProperty ("cookieName", DefaultValue = "ASP.NET_SessionId")]
124 public string CookieName {
125 get { return (string) base [cookieNameProp];}
126 set { base[cookieNameProp] = value; }
129 [ConfigurationProperty ("customProvider", DefaultValue = "")]
130 public string CustomProvider {
131 get { return (string) base [customProviderProp];}
132 set { base[customProviderProp] = value; }
135 [ConfigurationProperty ("mode", DefaultValue = "InProc")]
136 public SessionStateMode Mode {
137 get { return (SessionStateMode) base [modeProp];}
138 set { base[modeProp] = value; }
141 [ConfigurationProperty ("partitionResolverType", DefaultValue = "")]
142 public string PartitionResolverType {
143 get { return (string) base [partitionResolverTypeProp];}
144 set { base[partitionResolverTypeProp] = value; }
147 [ConfigurationProperty ("providers")]
148 public ProviderSettingsCollection Providers {
149 get { return (ProviderSettingsCollection) base [providersProp];}
152 [ConfigurationProperty ("regenerateExpiredSessionId", DefaultValue = "True")]
153 public bool RegenerateExpiredSessionId {
154 get { return (bool) base [regenerateExpiredSessionIdProp];}
155 set { base[regenerateExpiredSessionIdProp] = value; }
158 [ConfigurationProperty ("sessionIDManagerType", DefaultValue = "")]
159 public string SessionIDManagerType {
160 get { return (string) base [sessionIDManagerTypeProp];}
161 set { base[sessionIDManagerTypeProp] = value; }
164 [TypeConverter (typeof (TimeSpanSecondsOrInfiniteConverter))]
165 [ConfigurationProperty ("sqlCommandTimeout", DefaultValue = "00:00:30")]
166 public TimeSpan SqlCommandTimeout {
167 get { return (TimeSpan) base [sqlCommandTimeoutProp];}
168 set { base[sqlCommandTimeoutProp] = value; }
171 [ConfigurationProperty ("sqlConnectionString", DefaultValue = "data source=localhost;Integrated Security=SSPI")]
172 public string SqlConnectionString {
173 get { return (string) base [sqlConnectionStringProp];}
174 set { base[sqlConnectionStringProp] = value; }
177 [ConfigurationProperty ("stateConnectionString", DefaultValue = "tcpip=loopback:42424")]
178 public string StateConnectionString {
179 get { return (string) base [stateConnectionStringProp];}
180 set { base[stateConnectionStringProp] = value; }
183 [TypeConverter (typeof (TimeSpanSecondsOrInfiniteConverter))]
184 [ConfigurationProperty ("stateNetworkTimeout", DefaultValue = "00:00:10")]
185 // LAMESPEC: MS lists no validator here but provides one in Properties.
186 public TimeSpan StateNetworkTimeout {
187 get { return (TimeSpan) base [stateNetworkTimeoutProp];}
188 set { base[stateNetworkTimeoutProp] = value; }
191 [TypeConverter (typeof (TimeSpanMinutesOrInfiniteConverter))]
192 [TimeSpanValidator (MinValueString = "00:01:00", MaxValueString = "10675199.02:48:05.4775807")]
193 [ConfigurationProperty ("timeout", DefaultValue = "00:20:00")]
194 public TimeSpan Timeout {
195 get { return (TimeSpan) base [timeoutProp];}
196 set { base[timeoutProp] = value; }
199 [ConfigurationProperty ("useHostingIdentity", DefaultValue = "True")]
200 public bool UseHostingIdentity {
201 get { return (bool) base [useHostingIdentityProp];}
202 set { base[useHostingIdentityProp] = value; }
206 static void ValidateElement (object o)
208 /* XXX do some sort of element validation here? */
211 protected override ConfigurationElementProperty ElementProperty {
212 get { return elementProperty; }
215 protected override ConfigurationPropertyCollection Properties {
216 get { return properties; }
219 HttpCookieMode ParseCookieMode (string s)
221 if (s == "true") return HttpCookieMode.UseUri;
222 else if (s == "false") return HttpCookieMode.UseCookies;
225 return (HttpCookieMode)Enum.Parse (typeof(HttpCookieMode), s);
228 return HttpCookieMode.UseCookies;
233 #region CompatabilityCode
234 internal bool CookieLess {
235 get { return Cookieless != HttpCookieMode.UseCookies; }
236 set { Cookieless = value ? HttpCookieMode.UseUri : HttpCookieMode.UseCookies; }