AnonymousIdentificationSection.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 cookilessProp;
  48. static ConfigurationProperty domainProp;
  49. static AnonymousIdentificationSection ()
  50. {
  51. enabledProp = new ConfigurationProperty ("enabled", typeof(bool), false);
  52. cookielessProp = new ConfigurationProperty ("cookieless", typeof (HttpCookieMode), HttpCookieMode.UseCookies);
  53. cookieNameProp = new ConfigurationProperty ("cookieName", typeof (string), ".ASPXANONYMOUS", TypeDescriptor.GetConverter (typeof (string)),
  54. new StringValidator (1), ConfigurationPropertyOptions.None);
  55. cookieTimeoutProp = new ConfigurationProperty ("cookieTimeout", typeof (TimeSpan), new TimeSpan (69,10,40,0), new TimeSpanMinutesOrInfiniteConverter(),
  56. new TimeSpanValidator (TimeSpan.Zero, TimeSpan.MaxValue),
  57. ConfigurationPropertyOptions.None);
  58. cookiePathProp = new ConfigurationProperty ("cookiePath", typeof (string), "/", TypeDescriptor.GetConverter (typeof (string)),
  59. new StringValidator (1), ConfigurationPropertyOptions.None);
  60. cookieRequireSSLProp = new ConfigurationProperty ("cookieRequireSSL", typeof(bool), false);
  61. cookieSlidingExpirationProp = new ConfigurationProperty ("cookieSlidingExpiration", typeof(bool), true);
  62. cookieProtectionProp = new ConfigurationProperty ("cookieProtection", typeof(CookieProtection), CookieProtection.Validation);
  63. cookilessProp = new ConfigurationProperty ("cookiless", typeof(HttpCookieMode), HttpCookieMode.UseDeviceProfile);
  64. domainProp = new ConfigurationProperty ("domain", typeof(string), null);
  65. properties = new ConfigurationPropertyCollection ();
  66. properties.Add (enabledProp);
  67. properties.Add (cookielessProp);
  68. properties.Add (cookieNameProp);
  69. properties.Add (cookieTimeoutProp);
  70. properties.Add (cookiePathProp);
  71. properties.Add (cookieRequireSSLProp);
  72. properties.Add (cookieSlidingExpirationProp);
  73. properties.Add (cookieProtectionProp);
  74. properties.Add (cookilessProp);
  75. properties.Add (domainProp);
  76. }
  77. [ConfigurationProperty ("cookieless", DefaultValue = "UseCookies")]
  78. public HttpCookieMode Cookieless {
  79. get { return (HttpCookieMode) base [cookielessProp]; }
  80. set { base [cookielessProp] = value; }
  81. }
  82. [StringValidator (MinLength = 1)]
  83. [ConfigurationProperty ("cookieName", DefaultValue = ".ASPXANONYMOUS")]
  84. public string CookieName {
  85. get { return (string) base [cookieNameProp]; }
  86. set { base [cookieNameProp] = value; }
  87. }
  88. [StringValidator (MinLength = 1)]
  89. [ConfigurationProperty ("cookiePath", DefaultValue = "/")]
  90. public string CookiePath {
  91. get { return (string) base [cookiePathProp]; }
  92. set { base [cookiePathProp] = value; }
  93. }
  94. [ConfigurationProperty ("cookieProtection", DefaultValue = "Validation")]
  95. public CookieProtection CookieProtection {
  96. get { return (CookieProtection) base [cookieProtectionProp]; }
  97. set { base [cookieProtectionProp] = value; }
  98. }
  99. [ConfigurationProperty ("cookieRequireSSL", DefaultValue = "False")]
  100. public bool CookieRequireSSL {
  101. get { return (bool) base [cookieRequireSSLProp]; }
  102. set { base [cookieRequireSSLProp] = value; }
  103. }
  104. [ConfigurationProperty ("cookieSlidingExpiration", DefaultValue = "True")]
  105. public bool CookieSlidingExpiration {
  106. get { return (bool) base [cookieSlidingExpirationProp]; }
  107. set { base [cookieSlidingExpirationProp] = value; }
  108. }
  109. [TimeSpanValidator (MinValueString = "00:00:00", MaxValueString = "10675199.02:48:05.4775807")]
  110. [TypeConverter (typeof(TimeSpanMinutesOrInfiniteConverter))]
  111. [ConfigurationProperty ("cookieTimeout", DefaultValue = "69.10:40:00")]
  112. public TimeSpan CookieTimeout {
  113. get { return (TimeSpan) base [cookieTimeoutProp]; }
  114. set { base [cookieTimeoutProp] = value; }
  115. }
  116. [ConfigurationProperty ("domain")]
  117. public string Domain {
  118. get { return (string) base [domainProp]; }
  119. set { base [domainProp] = value; }
  120. }
  121. [ConfigurationProperty ("enabled", DefaultValue = "False")]
  122. public bool Enabled {
  123. get { return (bool) base [enabledProp]; }
  124. set { base [enabledProp] = value; }
  125. }
  126. protected override ConfigurationPropertyCollection Properties {
  127. get { return properties; }
  128. }
  129. }
  130. }
  131. #endif