2
0

PagesConfigurationHandler.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. bool bvalue = false;
  21. string attvalue = AttValue ("buffer", section);
  22. if (attvalue != null)
  23. config.Buffer = GetBool ("buffer", attvalue, section);
  24. attvalue = AttValue ("enableSessionState", section);
  25. if (attvalue != null) {
  26. if (attvalue != "true" && attvalue != "false" && attvalue != "ReadOnly")
  27. HandlersUtil.ThrowException ("Invalid value for 'enableSessionState'", section);
  28. config.EnableSessionState = attvalue;
  29. }
  30. attvalue = AttValue ("enableViewState", section);
  31. if (attvalue != null)
  32. config.EnableViewState = GetBool ("enableViewState", attvalue, section);
  33. attvalue = AttValue ("enableViewStateMac", section);
  34. if (attvalue != null)
  35. config.EnableViewStateMac = GetBool ("enableViewStateMac", attvalue, section);
  36. attvalue = AttValue ("smartNavigation", section);
  37. if (attvalue != null)
  38. config.SmartNavigation = GetBool ("smartNavigation", attvalue, section);
  39. attvalue = AttValue ("autoEventWireup", section);
  40. if (attvalue != null)
  41. config.AutoEventWireup = GetBool ("autoEventWireup", attvalue, section);
  42. attvalue = AttValue ("validateRequest", section);
  43. if (attvalue != null)
  44. config.ValidateRequest = GetBool ("validateRequest", attvalue, section);
  45. attvalue = AttValue ("pageBaseType", section);
  46. if (attvalue != null) {
  47. string v = attvalue.Trim ();
  48. if (v.Length == 0)
  49. HandlersUtil.ThrowException ("pageBaseType is empty.", section);
  50. config.PageBaseType = v;
  51. }
  52. attvalue = AttValue ("userControlBaseType", section);
  53. if (attvalue != null) {
  54. string v = attvalue.Trim ();
  55. if (v.Length == 0)
  56. HandlersUtil.ThrowException ("userControlBaseType is empty.", section);
  57. config.UserControlBaseType = v;
  58. }
  59. if (section.Attributes == null || section.Attributes.Count != 0)
  60. HandlersUtil.ThrowException ("Unknown attribute(s).", section);
  61. return config;
  62. }
  63. static bool GetBool (string name, string value, XmlNode section)
  64. {
  65. if (value == "true")
  66. return true;
  67. if (value != "false")
  68. HandlersUtil.ThrowException ("Invalid boolean value for '" + name + "'", section);
  69. return false;
  70. }
  71. // A few methods to save some typing
  72. static string AttValue (string name, XmlNode node, bool optional)
  73. {
  74. return HandlersUtil.ExtractAttributeValue (name, node, optional);
  75. }
  76. static string AttValue (string name, XmlNode node)
  77. {
  78. return HandlersUtil.ExtractAttributeValue (name, node, true);
  79. }
  80. //
  81. }
  82. }