PagesSection.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. //
  2. // System.Web.Configuration.PagesSection
  3. //
  4. // Authors:
  5. // Chris Toshok ([email protected])
  6. //
  7. // (C) 2005-2010 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. using System;
  30. using System.ComponentModel;
  31. using System.Configuration;
  32. using System.Web.UI;
  33. using System.Xml;
  34. namespace System.Web.Configuration
  35. {
  36. public sealed class PagesSection: ConfigurationSection
  37. {
  38. static ConfigurationPropertyCollection properties;
  39. static ConfigurationProperty asyncTimeoutProp;
  40. static ConfigurationProperty autoEventWireupProp;
  41. static ConfigurationProperty bufferProp;
  42. static ConfigurationProperty controlsProp;
  43. static ConfigurationProperty enableEventValidationProp;
  44. static ConfigurationProperty enableSessionStateProp;
  45. static ConfigurationProperty enableViewStateProp;
  46. static ConfigurationProperty enableViewStateMacProp;
  47. static ConfigurationProperty maintainScrollPositionOnPostBackProp;
  48. static ConfigurationProperty masterPageFileProp;
  49. static ConfigurationProperty maxPageStateFieldLengthProp;
  50. static ConfigurationProperty modeProp;
  51. static ConfigurationProperty namespacesProp;
  52. static ConfigurationProperty pageBaseTypeProp;
  53. static ConfigurationProperty pageParserFilterTypeProp;
  54. static ConfigurationProperty smartNavigationProp;
  55. static ConfigurationProperty styleSheetThemeProp;
  56. static ConfigurationProperty tagMappingProp;
  57. static ConfigurationProperty themeProp;
  58. static ConfigurationProperty userControlBaseTypeProp;
  59. static ConfigurationProperty validateRequestProp;
  60. static ConfigurationProperty viewStateEncryptionModeProp;
  61. #if NET_4_0
  62. static ConfigurationProperty clientIDModeProp;
  63. static ConfigurationProperty controlRenderingCompatibilityVersionProp;
  64. #endif
  65. static PagesSection ()
  66. {
  67. asyncTimeoutProp = new ConfigurationProperty ("asyncTimeout", typeof (TimeSpan), TimeSpan.FromSeconds (45.0),
  68. PropertyHelper.TimeSpanSecondsConverter,
  69. PropertyHelper.PositiveTimeSpanValidator,
  70. ConfigurationPropertyOptions.None);
  71. autoEventWireupProp = new ConfigurationProperty ("autoEventWireup", typeof(bool), true);
  72. bufferProp = new ConfigurationProperty ("buffer", typeof(bool), true);
  73. controlsProp = new ConfigurationProperty ("controls", typeof(TagPrefixCollection), null,
  74. null, null, ConfigurationPropertyOptions.None);
  75. enableEventValidationProp = new ConfigurationProperty ("enableEventValidation", typeof (bool), true);
  76. enableSessionStateProp = new ConfigurationProperty ("enableSessionState", typeof (string), "true");
  77. enableViewStateProp = new ConfigurationProperty ("enableViewState", typeof (bool), true);
  78. enableViewStateMacProp = new ConfigurationProperty ("enableViewStateMac", typeof (bool), true);
  79. maintainScrollPositionOnPostBackProp = new ConfigurationProperty ("maintainScrollPositionOnPostBack", typeof (bool), false);
  80. masterPageFileProp = new ConfigurationProperty ("masterPageFile", typeof (string), "");
  81. maxPageStateFieldLengthProp = new ConfigurationProperty ("maxPageStateFieldLength", typeof (int), -1);
  82. modeProp = new ConfigurationProperty ("compilationMode", typeof (CompilationMode), CompilationMode.Always,
  83. new GenericEnumConverter (typeof (CompilationMode)), PropertyHelper.DefaultValidator,
  84. ConfigurationPropertyOptions.None);
  85. namespacesProp = new ConfigurationProperty ("namespaces", typeof (NamespaceCollection), null,
  86. null, null, ConfigurationPropertyOptions.None);
  87. pageBaseTypeProp = new ConfigurationProperty ("pageBaseType", typeof (string), "System.Web.UI.Page");
  88. pageParserFilterTypeProp = new ConfigurationProperty ("pageParserFilterType", typeof (string), "");
  89. smartNavigationProp = new ConfigurationProperty ("smartNavigation", typeof (bool), false);
  90. styleSheetThemeProp = new ConfigurationProperty ("styleSheetTheme", typeof (string), "");
  91. tagMappingProp = new ConfigurationProperty ("tagMapping", typeof (TagMapCollection), null,
  92. null, null, ConfigurationPropertyOptions.None);
  93. themeProp = new ConfigurationProperty ("theme", typeof (string), "");
  94. userControlBaseTypeProp = new ConfigurationProperty ("userControlBaseType", typeof (string), "System.Web.UI.UserControl");
  95. validateRequestProp = new ConfigurationProperty ("validateRequest", typeof (bool), true);
  96. viewStateEncryptionModeProp = new ConfigurationProperty ("viewStateEncryptionMode", typeof (ViewStateEncryptionMode), ViewStateEncryptionMode.Auto,
  97. new GenericEnumConverter (typeof (ViewStateEncryptionMode)), PropertyHelper.DefaultValidator,
  98. ConfigurationPropertyOptions.None);
  99. #if NET_4_0
  100. clientIDModeProp = new ConfigurationProperty ("clientIDMode", typeof (ClientIDMode), ClientIDMode.Predictable,
  101. new GenericEnumConverter (typeof (ClientIDMode)), PropertyHelper.DefaultValidator,
  102. ConfigurationPropertyOptions.None);
  103. controlRenderingCompatibilityVersionProp = new ConfigurationProperty ("controlRenderingCompatibilityVersion", typeof (Version), new Version (4, 0),
  104. new VersionConverter (3, 5, "The value for the property 'controlRenderingCompatibilityVersion' is not valid. The error is: The control rendering compatibility version must not be less than {1}."),
  105. PropertyHelper.DefaultValidator,
  106. ConfigurationPropertyOptions.None);
  107. #endif
  108. properties = new ConfigurationPropertyCollection ();
  109. properties.Add (asyncTimeoutProp);
  110. properties.Add (autoEventWireupProp);
  111. properties.Add (bufferProp);
  112. properties.Add (controlsProp);
  113. properties.Add (enableEventValidationProp);
  114. properties.Add (enableSessionStateProp);
  115. properties.Add (enableViewStateProp);
  116. properties.Add (enableViewStateMacProp);
  117. properties.Add (maintainScrollPositionOnPostBackProp);
  118. properties.Add (masterPageFileProp);
  119. properties.Add (maxPageStateFieldLengthProp);
  120. properties.Add (modeProp);
  121. properties.Add (namespacesProp);
  122. properties.Add (pageBaseTypeProp);
  123. properties.Add (pageParserFilterTypeProp);
  124. properties.Add (smartNavigationProp);
  125. properties.Add (styleSheetThemeProp);
  126. properties.Add (tagMappingProp);
  127. properties.Add (themeProp);
  128. properties.Add (userControlBaseTypeProp);
  129. properties.Add (validateRequestProp);
  130. properties.Add (viewStateEncryptionModeProp);
  131. #if NET_4_0
  132. properties.Add (clientIDModeProp);
  133. properties.Add (controlRenderingCompatibilityVersionProp);
  134. #endif
  135. }
  136. public PagesSection ()
  137. {
  138. }
  139. [TimeSpanValidator (MinValueString = "00:00:00",
  140. MaxValueString = "10675199.02:48:05.4775807")]
  141. [TypeConverter (typeof (TimeSpanSecondsConverter))]
  142. [ConfigurationProperty ("asyncTimeout", DefaultValue = "00:00:45")]
  143. public TimeSpan AsyncTimeout {
  144. get { return (TimeSpan) base [asyncTimeoutProp]; }
  145. set { base [asyncTimeoutProp] = value; }
  146. }
  147. [ConfigurationProperty ("autoEventWireup", DefaultValue = true)]
  148. public bool AutoEventWireup {
  149. get { return (bool) base [autoEventWireupProp]; }
  150. set { base [autoEventWireupProp] = value; }
  151. }
  152. [ConfigurationProperty ("buffer", DefaultValue = true)]
  153. public bool Buffer {
  154. get { return (bool) base [bufferProp]; }
  155. set { base [bufferProp] = value; }
  156. }
  157. [ConfigurationProperty ("compilationMode", DefaultValue = CompilationMode.Always)]
  158. public CompilationMode CompilationMode {
  159. get { return (CompilationMode) base [modeProp]; }
  160. set { base [modeProp] = value; }
  161. }
  162. [ConfigurationProperty ("controls")]
  163. public TagPrefixCollection Controls {
  164. get { return (TagPrefixCollection) base[controlsProp]; }
  165. }
  166. [ConfigurationProperty ("enableEventValidation", DefaultValue = true)]
  167. public bool EnableEventValidation {
  168. get { return (bool) base[enableEventValidationProp]; }
  169. set { base[enableEventValidationProp] = value; }
  170. }
  171. [ConfigurationProperty ("enableSessionState", DefaultValue = "true")]
  172. public PagesEnableSessionState EnableSessionState {
  173. get {
  174. string enableSessionState = (string) base [enableSessionStateProp];
  175. switch (enableSessionState) {
  176. case "true":
  177. return PagesEnableSessionState.True;
  178. case "false":
  179. return PagesEnableSessionState.False;
  180. case "ReadOnly":
  181. return PagesEnableSessionState.ReadOnly;
  182. }
  183. throw new ConfigurationErrorsException ("The 'enableSessionState'"
  184. + " attribute must be one of the following values: true,"
  185. + "false, ReadOnly.");
  186. }
  187. set {
  188. switch (value) {
  189. case PagesEnableSessionState.False:
  190. base [enableSessionStateProp] = "false";
  191. break;
  192. case PagesEnableSessionState.ReadOnly:
  193. base [enableSessionStateProp] = "ReadOnly";
  194. break;
  195. default:
  196. base [enableSessionStateProp] = "true";
  197. break;
  198. }
  199. }
  200. }
  201. [ConfigurationProperty ("enableViewState", DefaultValue = true)]
  202. public bool EnableViewState {
  203. get { return (bool) base[enableViewStateProp]; }
  204. set { base[enableViewStateProp] = value; }
  205. }
  206. [ConfigurationProperty ("enableViewStateMac", DefaultValue = true)]
  207. public bool EnableViewStateMac {
  208. get { return (bool) base[enableViewStateMacProp]; }
  209. set { base[enableViewStateMacProp] = value; }
  210. }
  211. [ConfigurationProperty ("maintainScrollPositionOnPostBack", DefaultValue = false)]
  212. public bool MaintainScrollPositionOnPostBack {
  213. get { return (bool) base[maintainScrollPositionOnPostBackProp]; }
  214. set { base [maintainScrollPositionOnPostBackProp] = value; }
  215. }
  216. [ConfigurationProperty ("masterPageFile", DefaultValue = "")]
  217. public string MasterPageFile {
  218. get { return (string) base[masterPageFileProp]; }
  219. set { base[masterPageFileProp] = value; }
  220. }
  221. [ConfigurationProperty ("maxPageStateFieldLength", DefaultValue = -1)]
  222. public int MaxPageStateFieldLength {
  223. get { return (int) base[maxPageStateFieldLengthProp]; }
  224. set { base[maxPageStateFieldLengthProp] = value; }
  225. }
  226. [ConfigurationProperty ("namespaces")]
  227. public NamespaceCollection Namespaces {
  228. get { return (NamespaceCollection) base[namespacesProp]; }
  229. }
  230. [ConfigurationProperty ("pageBaseType", DefaultValue = "System.Web.UI.Page")]
  231. public string PageBaseType {
  232. get { return (string) base[pageBaseTypeProp]; }
  233. set { base[pageBaseTypeProp] = value; }
  234. }
  235. [ConfigurationProperty ("pageParserFilterType", DefaultValue = "")]
  236. public string PageParserFilterType {
  237. get { return (string) base[pageParserFilterTypeProp]; }
  238. set { base [pageParserFilterTypeProp] = value; }
  239. }
  240. [ConfigurationProperty ("smartNavigation", DefaultValue = false)]
  241. public bool SmartNavigation {
  242. get { return (bool) base[smartNavigationProp]; }
  243. set { base[smartNavigationProp] = value; }
  244. }
  245. [ConfigurationProperty ("styleSheetTheme", DefaultValue = "")]
  246. public string StyleSheetTheme {
  247. get { return (string) base[styleSheetThemeProp]; }
  248. set { base[styleSheetThemeProp] = value; }
  249. }
  250. [ConfigurationProperty ("tagMapping")]
  251. public TagMapCollection TagMapping {
  252. get { return (TagMapCollection) base [tagMappingProp]; }
  253. }
  254. [ConfigurationProperty ("theme", DefaultValue = "")]
  255. public string Theme {
  256. get { return (string) base[themeProp]; }
  257. set { base[themeProp] = value; }
  258. }
  259. [ConfigurationProperty ("userControlBaseType", DefaultValue = "System.Web.UI.UserControl")]
  260. public string UserControlBaseType {
  261. get { return (string) base[userControlBaseTypeProp]; }
  262. set { base[userControlBaseTypeProp] = value; }
  263. }
  264. [ConfigurationProperty ("validateRequest", DefaultValue = true)]
  265. public bool ValidateRequest {
  266. get { return (bool) base[validateRequestProp]; }
  267. set { base[validateRequestProp] = value; }
  268. }
  269. [ConfigurationProperty ("viewStateEncryptionMode", DefaultValue = ViewStateEncryptionMode.Auto)]
  270. public ViewStateEncryptionMode ViewStateEncryptionMode {
  271. get { return (ViewStateEncryptionMode) base [viewStateEncryptionModeProp]; }
  272. set { base [viewStateEncryptionModeProp] = value; }
  273. }
  274. #if NET_4_0
  275. [ConfigurationProperty ("clientIDMode", DefaultValue = ClientIDMode.Predictable)]
  276. public ClientIDMode ClientIDMode {
  277. get { return (ClientIDMode) base [clientIDModeProp]; }
  278. set { base [clientIDModeProp] = value; }
  279. }
  280. [ConfigurationProperty ("controlRenderingCompatibilityVersion", DefaultValue = "4.0")]
  281. public Version ControlRenderingCompatibilityVersion {
  282. get { return (Version) base [controlRenderingCompatibilityVersionProp]; }
  283. set {
  284. if (value == null)
  285. throw new ArgumentNullException ("value");
  286. base [controlRenderingCompatibilityVersionProp] = value;
  287. }
  288. }
  289. #endif
  290. protected override ConfigurationPropertyCollection Properties {
  291. get { return properties; }
  292. }
  293. protected override void DeserializeSection (XmlReader reader)
  294. {
  295. base.DeserializeSection (reader);
  296. /* XXX more here?.. */
  297. }
  298. }
  299. }