HttpModulesConfigurationHandler.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // System.Web.Configuration.HttpModulesConfigurationHandler
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2002 Ximian, Inc (http://www.ximian.com)
  8. //
  9. using System.Configuration;
  10. using System.Xml;
  11. using System.Web.Security;
  12. namespace System.Web.Configuration
  13. {
  14. class HttpModulesConfigurationHandler : IConfigurationSectionHandler
  15. {
  16. public virtual object Create (object parent, object configContext, XmlNode section)
  17. {
  18. ModulesConfiguration mapper;
  19. if (parent is ModulesConfiguration)
  20. mapper = new ModulesConfiguration ((ModulesConfiguration) parent);
  21. else
  22. mapper = new ModulesConfiguration ();
  23. if (section.Attributes != null && section.Attributes.Count != 0)
  24. HandlersUtil.ThrowException ("Unrecognized attribute", section);
  25. XmlNodeList httpModules = section.ChildNodes;
  26. foreach (XmlNode child in httpModules) {
  27. XmlNodeType ntype = child.NodeType;
  28. if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
  29. continue;
  30. if (ntype != XmlNodeType.Element)
  31. HandlersUtil.ThrowException ("Only elements allowed", child);
  32. string name = child.Name;
  33. if (name == "clear") {
  34. if (child.Attributes.Count != 0)
  35. HandlersUtil.ThrowException ("Unrecognized attribute", child);
  36. mapper.Clear ();
  37. continue;
  38. }
  39. string nameAtt = HandlersUtil.ExtractAttributeValue ("name", child);
  40. if (name == "add") {
  41. string type = HandlersUtil.ExtractAttributeValue ("type", child);
  42. if (child.Attributes.Count != 0)
  43. HandlersUtil.ThrowException ("Unrecognized attribute", child);
  44. // FIXME: gotta remove this. Just here to make it work with my local config
  45. if (type.StartsWith ("System.Web.Mobile"))
  46. continue;
  47. ModuleItem item = new ModuleItem (nameAtt, type);
  48. mapper.Add (item);
  49. continue;
  50. }
  51. if (name == "remove") {
  52. if (child.Attributes.Count != 0)
  53. HandlersUtil.ThrowException ("Unrecognized attribute", child);
  54. if (mapper.Remove (nameAtt) == null)
  55. HandlersUtil.ThrowException ("Module not loaded", child);
  56. continue;
  57. }
  58. HandlersUtil.ThrowException ("Unrecognized element", child);
  59. }
  60. mapper.Add (new ModuleItem ("DefaultAuthentication", typeof (DefaultAuthenticationModule)));
  61. return mapper;
  62. }
  63. }
  64. }