PagesConfigurationHandler.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. using System.Configuration;
  10. using System.Xml;
  11. namespace System.Web.Configuration
  12. {
  13. class PagesConfigurationHandler : IConfigurationSectionHandler
  14. {
  15. public object Create (object parent, object configContext, XmlNode section)
  16. {
  17. PagesConfiguration config = new PagesConfiguration (parent);
  18. if (section.HasChildNodes)
  19. HandlersUtil.ThrowException ("No child nodes allowed here.", section);
  20. string attvalue = AttValue ("buffer", section);
  21. if (attvalue != null)
  22. config.Buffer = GetBool ("buffer", attvalue, section);
  23. attvalue = AttValue ("enableSessionState", section);
  24. if (attvalue != null) {
  25. if (attvalue != "true" && attvalue != "false" && attvalue != "ReadOnly")
  26. HandlersUtil.ThrowException ("Invalid value for 'enableSessionState'", section);
  27. config.EnableSessionState = attvalue;
  28. }
  29. attvalue = AttValue ("enableViewState", section);
  30. if (attvalue != null)
  31. config.EnableViewState = GetBool ("enableViewState", attvalue, section);
  32. attvalue = AttValue ("enableViewStateMac", section);
  33. if (attvalue != null)
  34. config.EnableViewStateMac = GetBool ("enableViewStateMac", attvalue, section);
  35. attvalue = AttValue ("smartNavigation", section);
  36. if (attvalue != null)
  37. config.SmartNavigation = GetBool ("smartNavigation", attvalue, section);
  38. attvalue = AttValue ("autoEventWireup", section);
  39. if (attvalue != null)
  40. config.AutoEventWireup = GetBool ("autoEventWireup", attvalue, section);
  41. attvalue = AttValue ("validateRequest", section);
  42. if (attvalue != null)
  43. config.ValidateRequest = GetBool ("validateRequest", attvalue, section);
  44. attvalue = AttValue ("pageBaseType", section);
  45. if (attvalue != null) {
  46. string v = attvalue.Trim ();
  47. if (v.Length == 0)
  48. HandlersUtil.ThrowException ("pageBaseType is empty.", section);
  49. config.PageBaseType = v;
  50. }
  51. attvalue = AttValue ("userControlBaseType", section);
  52. if (attvalue != null) {
  53. string v = attvalue.Trim ();
  54. if (v.Length == 0)
  55. HandlersUtil.ThrowException ("userControlBaseType is empty.", section);
  56. config.UserControlBaseType = v;
  57. }
  58. if (section.Attributes == null || section.Attributes.Count != 0)
  59. HandlersUtil.ThrowException ("Unknown attribute(s).", section);
  60. return config;
  61. }
  62. static bool GetBool (string name, string value, XmlNode section)
  63. {
  64. if (value == "true")
  65. return true;
  66. if (value != "false")
  67. HandlersUtil.ThrowException ("Invalid boolean value for '" + name + "'", section);
  68. return false;
  69. }
  70. // A few methods to save some typing
  71. static string AttValue (string name, XmlNode node, bool optional)
  72. {
  73. return HandlersUtil.ExtractAttributeValue (name, node, optional);
  74. }
  75. static string AttValue (string name, XmlNode node)
  76. {
  77. return HandlersUtil.ExtractAttributeValue (name, node, true);
  78. }
  79. //
  80. }
  81. }