PagesConfigurationHandler.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // System.Web.Configuration.PagesConfigurationHandler
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2004 Novell, Inc (http://www.novel.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.Configuration;
  30. using System.Xml;
  31. namespace System.Web.Configuration
  32. {
  33. class PagesConfigurationHandler : IConfigurationSectionHandler
  34. {
  35. public object Create (object parent, object configContext, XmlNode section)
  36. {
  37. PagesConfiguration config = new PagesConfiguration (parent);
  38. if (section.HasChildNodes)
  39. HandlersUtil.ThrowException ("No child nodes allowed here.", section);
  40. string attvalue = AttValue ("buffer", section);
  41. if (attvalue != null)
  42. config.Buffer = GetBool ("buffer", attvalue, section);
  43. attvalue = AttValue ("enableSessionState", section);
  44. if (attvalue != null) {
  45. if (attvalue != "true" && attvalue != "false" && attvalue != "ReadOnly")
  46. HandlersUtil.ThrowException ("Invalid value for 'enableSessionState'", section);
  47. config.EnableSessionState = attvalue;
  48. }
  49. attvalue = AttValue ("enableViewState", section);
  50. if (attvalue != null)
  51. config.EnableViewState = GetBool ("enableViewState", attvalue, section);
  52. attvalue = AttValue ("enableViewStateMac", section);
  53. if (attvalue != null)
  54. config.EnableViewStateMac = GetBool ("enableViewStateMac", attvalue, section);
  55. attvalue = AttValue ("smartNavigation", section);
  56. if (attvalue != null)
  57. config.SmartNavigation = GetBool ("smartNavigation", attvalue, section);
  58. attvalue = AttValue ("autoEventWireup", section);
  59. if (attvalue != null)
  60. config.AutoEventWireup = GetBool ("autoEventWireup", attvalue, section);
  61. attvalue = AttValue ("validateRequest", section);
  62. if (attvalue != null)
  63. config.ValidateRequest = GetBool ("validateRequest", attvalue, section);
  64. attvalue = AttValue ("pageBaseType", section);
  65. if (attvalue != null) {
  66. string v = attvalue.Trim ();
  67. if (v.Length == 0)
  68. HandlersUtil.ThrowException ("pageBaseType is empty.", section);
  69. config.PageBaseType = v;
  70. }
  71. attvalue = AttValue ("userControlBaseType", section);
  72. if (attvalue != null) {
  73. string v = attvalue.Trim ();
  74. if (v.Length == 0)
  75. HandlersUtil.ThrowException ("userControlBaseType is empty.", section);
  76. config.UserControlBaseType = v;
  77. }
  78. if (section.Attributes == null || section.Attributes.Count != 0)
  79. HandlersUtil.ThrowException ("Unknown attribute(s).", section);
  80. return config;
  81. }
  82. static bool GetBool (string name, string value, XmlNode section)
  83. {
  84. if (value == "true")
  85. return true;
  86. if (value != "false")
  87. HandlersUtil.ThrowException ("Invalid boolean value for '" + name + "'", section);
  88. return false;
  89. }
  90. // A few methods to save some typing
  91. static string AttValue (string name, XmlNode node, bool optional)
  92. {
  93. return HandlersUtil.ExtractAttributeValue (name, node, optional);
  94. }
  95. static string AttValue (string name, XmlNode node)
  96. {
  97. return HandlersUtil.ExtractAttributeValue (name, node, true);
  98. }
  99. //
  100. }
  101. }