PagesConfigurationHandler.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 ("The 'enableSessionState' attribute"
  47. + " is case sensitive and must be one of the following values:"
  48. + " false, true, ReadOnly.", section);
  49. config.EnableSessionState = attvalue;
  50. }
  51. attvalue = AttValue ("enableViewState", section);
  52. if (attvalue != null)
  53. config.EnableViewState = GetBool ("enableViewState", attvalue, section);
  54. attvalue = AttValue ("enableViewStateMac", section);
  55. if (attvalue != null)
  56. config.EnableViewStateMac = GetBool ("enableViewStateMac", attvalue, section);
  57. attvalue = AttValue ("smartNavigation", section);
  58. if (attvalue != null)
  59. config.SmartNavigation = GetBool ("smartNavigation", attvalue, section);
  60. attvalue = AttValue ("autoEventWireup", section);
  61. if (attvalue != null)
  62. config.AutoEventWireup = GetBool ("autoEventWireup", attvalue, section);
  63. attvalue = AttValue ("validateRequest", section);
  64. if (attvalue != null)
  65. config.ValidateRequest = GetBool ("validateRequest", attvalue, section);
  66. attvalue = AttValue ("pageBaseType", section);
  67. if (attvalue != null) {
  68. string v = attvalue.Trim ();
  69. if (v.Length == 0)
  70. HandlersUtil.ThrowException ("pageBaseType is empty.", section);
  71. config.PageBaseType = v;
  72. }
  73. attvalue = AttValue ("userControlBaseType", section);
  74. if (attvalue != null) {
  75. string v = attvalue.Trim ();
  76. if (v.Length == 0)
  77. HandlersUtil.ThrowException ("userControlBaseType is empty.", section);
  78. config.UserControlBaseType = v;
  79. }
  80. if (section.Attributes == null || section.Attributes.Count != 0)
  81. HandlersUtil.ThrowException ("Unknown attribute(s).", section);
  82. return config;
  83. }
  84. static bool GetBool (string name, string value, XmlNode section)
  85. {
  86. if (value == "true")
  87. return true;
  88. if (value != "false")
  89. HandlersUtil.ThrowException ("Invalid boolean value for '" + name + "'", section);
  90. return false;
  91. }
  92. // A few methods to save some typing
  93. static string AttValue (string name, XmlNode node)
  94. {
  95. return HandlersUtil.ExtractAttributeValue (name, node, true);
  96. }
  97. //
  98. }
  99. }