1 //
2 // System.Web.Configuration.AnonymousIdentificationSection.cs
3 //
4 // Authors:
5 //	Lluis Sanchez Gual (lluis@novell.com)
6 //
7 // (C) 2004 Novell, Inc (http://www.novell.com)
8 //
9 
10 //
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:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
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.
29 //
30 
31 
32 using System;
33 using System.Configuration;
34 using System.Web.Security;
35 using System.ComponentModel;
36 
37 namespace System.Web.Configuration
38 {
39 	public sealed class AnonymousIdentificationSection: ConfigurationSection
40 	{
41 		static ConfigurationPropertyCollection properties;
42 		static ConfigurationProperty enabledProp;
43 		static ConfigurationProperty cookielessProp;
44 		static ConfigurationProperty cookieNameProp;
45 		static ConfigurationProperty cookieTimeoutProp;
46 		static ConfigurationProperty cookiePathProp;
47 		static ConfigurationProperty cookieRequireSSLProp;
48 		static ConfigurationProperty cookieSlidingExpirationProp;
49 		static ConfigurationProperty cookieProtectionProp;
50 		static ConfigurationProperty domainProp;
51 
AnonymousIdentificationSection()52 		static AnonymousIdentificationSection ()
53 		{
54 			enabledProp = new ConfigurationProperty ("enabled", typeof(bool), false);
55 			cookielessProp = new ConfigurationProperty ("cookieless", typeof (HttpCookieMode), HttpCookieMode.UseCookies,
56 								    new GenericEnumConverter (typeof (HttpCookieMode)),
57 								    PropertyHelper.DefaultValidator,
58 								    ConfigurationPropertyOptions.None);
59 			cookieNameProp = new ConfigurationProperty ("cookieName", typeof (string), ".ASPXANONYMOUS", TypeDescriptor.GetConverter (typeof (string)),
60 								    PropertyHelper.NonEmptyStringValidator, ConfigurationPropertyOptions.None);
61 			cookieTimeoutProp = new ConfigurationProperty ("cookieTimeout", typeof (TimeSpan), new TimeSpan (69,10,40,0), new TimeSpanMinutesOrInfiniteConverter(),
62 								       PropertyHelper.PositiveTimeSpanValidator,
63 								       ConfigurationPropertyOptions.None);
64 			cookiePathProp = new ConfigurationProperty ("cookiePath", typeof (string), "/", TypeDescriptor.GetConverter (typeof (string)),
65 								    PropertyHelper.NonEmptyStringValidator, ConfigurationPropertyOptions.None);
66 			cookieRequireSSLProp = new ConfigurationProperty ("cookieRequireSSL", typeof(bool), false);
67 			cookieSlidingExpirationProp = new ConfigurationProperty ("cookieSlidingExpiration", typeof(bool), true);
68 			cookieProtectionProp = new ConfigurationProperty ("cookieProtection", typeof(CookieProtection), CookieProtection.Validation,
69 									  new GenericEnumConverter (typeof (CookieProtection)),
70 									  null, ConfigurationPropertyOptions.None);
71 
72 			domainProp = new ConfigurationProperty ("domain", typeof(string), null);
73 
74 			properties = new ConfigurationPropertyCollection ();
75 			properties.Add (enabledProp);
76 			properties.Add (cookielessProp);
77 			properties.Add (cookieNameProp);
78 			properties.Add (cookieTimeoutProp);
79 			properties.Add (cookiePathProp);
80 			properties.Add (cookieRequireSSLProp);
81 			properties.Add (cookieSlidingExpirationProp);
82 			properties.Add (cookieProtectionProp);
83 			properties.Add (domainProp);
84 		}
85 
86 		[ConfigurationProperty ("cookieless", DefaultValue = "UseCookies")]
87 		public HttpCookieMode Cookieless {
88 			get { return (HttpCookieMode) base [cookielessProp]; }
89 			set { base [cookielessProp] = value; }
90 		}
91 
92 		[StringValidator (MinLength = 1)]
93 		[ConfigurationProperty ("cookieName", DefaultValue = ".ASPXANONYMOUS")]
94 		public string CookieName {
95 			get { return (string) base [cookieNameProp]; }
96 			set { base [cookieNameProp] = value; }
97 		}
98 
99 		[StringValidator (MinLength = 1)]
100 		[ConfigurationProperty ("cookiePath", DefaultValue = "/")]
101 		public string CookiePath {
102 			get { return (string) base [cookiePathProp]; }
103 			set { base [cookiePathProp] = value; }
104 		}
105 
106 		[ConfigurationProperty ("cookieProtection", DefaultValue = "Validation")]
107 		public CookieProtection CookieProtection {
108 			get { return (CookieProtection) base [cookieProtectionProp]; }
109 			set { base [cookieProtectionProp] = value; }
110 		}
111 
112 		[ConfigurationProperty ("cookieRequireSSL", DefaultValue = "False")]
113 		public bool CookieRequireSSL {
114 			get { return (bool) base [cookieRequireSSLProp]; }
115 			set { base [cookieRequireSSLProp] = value; }
116 		}
117 
118 		[ConfigurationProperty ("cookieSlidingExpiration", DefaultValue = "True")]
119 		public bool CookieSlidingExpiration {
120 			get { return (bool) base [cookieSlidingExpirationProp]; }
121 			set { base [cookieSlidingExpirationProp] = value; }
122 		}
123 
124 		[TimeSpanValidator (MinValueString = "00:00:00", MaxValueString = "10675199.02:48:05.4775807")]
125 		[TypeConverter (typeof(TimeSpanMinutesOrInfiniteConverter))]
126 		[ConfigurationProperty ("cookieTimeout", DefaultValue = "69.10:40:00")]
127 		public TimeSpan CookieTimeout {
128 			get { return (TimeSpan) base [cookieTimeoutProp]; }
129 			set { base [cookieTimeoutProp] = value; }
130 		}
131 
132 		[ConfigurationProperty ("domain")]
133 		public string Domain {
134 			get { return (string) base [domainProp]; }
135 			set { base [domainProp] = value; }
136 		}
137 
138 		[ConfigurationProperty ("enabled", DefaultValue = "False")]
139 		public bool Enabled {
140 			get { return (bool) base [enabledProp]; }
141 			set { base [enabledProp] = value; }
142 		}
143 
144 		protected internal override ConfigurationPropertyCollection Properties {
145 			get { return properties; }
146 		}
147 	}
148 }
149 
150