2 // System.Web.Configuration.HttpModulesConfigurationHandler
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2002 Ximian, Inc (http://www.ximian.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Configuration;
33 using System.Web.Security;
35 namespace System.Web.Configuration
37 class HttpModulesConfigurationHandler : IConfigurationSectionHandler
39 public virtual object Create (object parent, object configContext, XmlNode section)
41 ModulesConfiguration mapper;
43 if (parent is ModulesConfiguration)
44 mapper = new ModulesConfiguration ((ModulesConfiguration) parent);
46 mapper = new ModulesConfiguration (null);
48 if (section.Attributes != null && section.Attributes.Count != 0)
49 HandlersUtil.ThrowException ("Unrecognized attribute", section);
51 XmlNodeList httpModules = section.ChildNodes;
53 foreach (XmlNode child in httpModules) {
54 XmlNodeType ntype = child.NodeType;
55 if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
58 if (ntype != XmlNodeType.Element)
59 HandlersUtil.ThrowException ("Only elements allowed", child);
61 string name = child.Name;
62 if (name == "clear") {
63 if (child.Attributes.Count != 0)
64 HandlersUtil.ThrowException ("Unrecognized attribute", child);
70 string name_attr = HandlersUtil.ExtractAttributeValue ("name", child);
72 string type = HandlersUtil.ExtractAttributeValue ("type", child);
73 if (child.Attributes.Count != 0)
74 HandlersUtil.ThrowException ("Unrecognized attribute", child);
76 // FIXME: gotta remove this. Just here to make it work with my local config
77 if (type.StartsWith ("System.Web.Mobile"))
80 mapper.Add (name_attr, type);
84 if (name == "remove") {
85 if (child.Attributes.Count != 0)
86 HandlersUtil.ThrowException ("Unrecognized attribute", child);
88 if (mapper.Remove (name_attr) == null)
89 HandlersUtil.ThrowException ("Module not loaded", child);
93 HandlersUtil.ThrowException ("Unrecognized element", child);
96 mapper.Add ("DefaultAuthentication", typeof (DefaultAuthenticationModule));