AnonymousIdentificationSection.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // System.Web.Configuration.AnonymousIdentificationSection.cs
  3. //
  4. // Authors:
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // (C) 2004 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. #if NET_2_0
  30. using System;
  31. using System.Configuration;
  32. using System.Web.Security;
  33. using System.ComponentModel;
  34. namespace System.Web.Configuration
  35. {
  36. public sealed class AnonymousIdentificationSection: ConfigurationSection
  37. {
  38. static ConfigurationPropertyCollection properties;
  39. static ConfigurationProperty enabledProp;
  40. static ConfigurationProperty cookielessProp;
  41. static ConfigurationProperty cookieNameProp;
  42. static ConfigurationProperty cookieTimeoutProp;
  43. static ConfigurationProperty cookiePathProp;
  44. static ConfigurationProperty cookieRequireSSLProp;
  45. static ConfigurationProperty cookieSlidingExpirationProp;
  46. static ConfigurationProperty cookieProtectionProp;
  47. static ConfigurationProperty domainProp;
  48. static AnonymousIdentificationSection ()
  49. {
  50. enabledProp = new ConfigurationProperty ("enabled", typeof(bool), false);
  51. cookielessProp = new ConfigurationProperty ("cookieless", typeof (HttpCookieMode), HttpCookieMode.UseCookies,
  52. new GenericEnumConverter (typeof (HttpCookieMode)),
  53. PropertyHelper.DefaultValidator,
  54. ConfigurationPropertyOptions.None);
  55. cookieNameProp = new ConfigurationProperty ("cookieName", typeof (string), ".ASPXANONYMOUS", TypeDescriptor.GetConverter (typeof (string)),
  56. PropertyHelper.NonEmptyStringValidator, ConfigurationPropertyOptions.None);
  57. cookieTimeoutProp = new ConfigurationProperty ("cookieTimeout", typeof (TimeSpan), new TimeSpan (69,10,40,0), new TimeSpanMinutesOrInfiniteConverter(),
  58. PropertyHelper.PositiveTimeSpanValidator,
  59. ConfigurationPropertyOptions.None);
  60. cookiePathProp = new ConfigurationProperty ("cookiePath", typeof (string), "/", TypeDescriptor.GetConverter (typeof (string)),
  61. PropertyHelper.NonEmptyStringValidator, ConfigurationPropertyOptions.None);
  62. cookieRequireSSLProp = new ConfigurationProperty ("cookieRequireSSL", typeof(bool), false);
  63. cookieSlidingExpirationProp = new ConfigurationProperty ("cookieSlidingExpiration", typeof(bool), true);
  64. cookieProtectionProp = new ConfigurationProperty ("cookieProtection", typeof(CookieProtection), CookieProtection.Validation,
  65. new GenericEnumConverter (typeof (CookieProtection)),
  66. null, ConfigurationPropertyOptions.None);
  67. domainProp = new ConfigurationProperty ("domain", typeof(string), null);
  68. properties = new ConfigurationPropertyCollection ();
  69. properties.Add (enabledProp);
  70. properties.Add (cookielessProp);
  71. properties.Add (cookieNameProp);
  72. properties.Add (cookieTimeoutProp);
  73. properties.Add (cookiePathProp);
  74. properties.Add (cookieRequireSSLProp);
  75. properties.Add (cookieSlidingExpirationProp);
  76. properties.Add (cookieProtectionProp);
  77. properties.Add (domainProp);
  78. }
  79. [ConfigurationProperty ("cookieless", DefaultValue = "UseCookies")]
  80. public HttpCookieMode Cookieless {
  81. get { return (HttpCookieMode) base [cookielessProp]; }
  82. set { base [cookielessProp] = value; }
  83. }
  84. [StringValidator (MinLength = 1)]
  85. [ConfigurationProperty ("cookieName", DefaultValue = ".ASPXANONYMOUS")]
  86. public string CookieName {
  87. get { return (string) base [cookieNameProp]; }
  88. set { base [cookieNameProp] = value; }
  89. }
  90. [StringValidator (MinLength = 1)]
  91. [ConfigurationProperty ("cookiePath", DefaultValue = "/")]
  92. public string CookiePath {
  93. get { return (string) base [cookiePathProp]; }
  94. set { base [cookiePathProp] = value; }
  95. }
  96. [ConfigurationProperty ("cookieProtection", DefaultValue = "Validation")]
  97. public CookieProtection CookieProtection {
  98. get { return (CookieProtection) base [cookieProtectionProp]; }
  99. set { base [cookieProtectionProp] = value; }
  100. }
  101. [ConfigurationProperty ("cookieRequireSSL", DefaultValue = "False")]
  102. public bool CookieRequireSSL {
  103. get { return (bool) base [cookieRequireSSLProp]; }
  104. set { base [cookieRequireSSLProp] = value; }
  105. }
  106. [ConfigurationProperty ("cookieSlidingExpiration", DefaultValue = "True")]
  107. public bool CookieSlidingExpiration {
  108. get { return (bool) base [cookieSlidingExpirationProp]; }
  109. set { base [cookieSlidingExpirationProp] = value; }
  110. }
  111. [TimeSpanValidator (MinValueString = "00:00:00", MaxValueString = "10675199.02:48:05.4775807")]
  112. [TypeConverter (typeof(TimeSpanMinutesOrInfiniteConverter))]
  113. [ConfigurationProperty ("cookieTimeout", DefaultValue = "69.10:40:00")]
  114. public TimeSpan CookieTimeout {
  115. get { return (TimeSpan) base [cookieTimeoutProp]; }
  116. set { base [cookieTimeoutProp] = value; }
  117. }
  118. [ConfigurationProperty ("domain")]
  119. public string Domain {
  120. get { return (string) base [domainProp]; }
  121. set { base [domainProp] = value; }
  122. }
  123. [ConfigurationProperty ("enabled", DefaultValue = "False")]
  124. public bool Enabled {
  125. get { return (bool) base [enabledProp]; }
  126. set { base [enabledProp] = value; }
  127. }
  128. protected override ConfigurationPropertyCollection Properties {
  129. get { return properties; }
  130. }
  131. }
  132. }
  133. #endif