static void ReadCredentials(XmlNodeList nodes, AuthConfig config) { foreach (XmlNode child in nodes) { XmlNodeType ntype = child.NodeType; if (ntype != XmlNodeType.Element) { continue; } if (child.Name != "credentials") { HandlersUtil.ThrowException("Unexpected element", child); } config.SetPasswordFormat(AttValue("passwordFormat", child)); ReadUsers(child.ChildNodes, config.CredentialUsers); } }
public object Create(object parent, object context, XmlNode section) { AuthConfig config = new AuthConfig(parent); string mode = AttValue("mode", section); if (mode != null) { config.SetMode(mode); } if (section.Attributes != null && section.Attributes.Count != 0) { ThrowException("Unrecognized attribute", section); } XmlNodeList authNodes = section.ChildNodes; foreach (XmlNode child in authNodes) { XmlNodeType ntype = child.NodeType; if (ntype != XmlNodeType.Element) { continue; } if (child.Name == "forms") { config.CookieName = AttValue("name", child); config.CookiePath = AttValue("path", child); config.LoginUrl = AttValue("loginUrl", child); config.SetProtection(AttValue("protection", child)); config.SetTimeout(AttValue("timeout", child)); #if NET_1_1 string att = AttValue("requireSSL", child); if (att != null) { if (att == "true") { config.RequireSSL = true; } else if (att == "false") { config.RequireSSL = false; } else { HandlersUtil.ThrowException ("Invalid value for RequireSSL", child); } } att = AttValue("slidingExpiration", child); if (att != null) { if (att == "true") { config.SlidingExpiration = true; } else if (att == "false") { config.SlidingExpiration = false; } else { HandlersUtil.ThrowException ("Invalid value for SlidingExpiration", child); } } #endif ReadCredentials(child.ChildNodes, config); continue; } if (child.Name == "passport") { continue; } HandlersUtil.ThrowException("Unexpected element", child); } return(config); }
static void ThrowException(string message, XmlNode node) { HandlersUtil.ThrowException(message, node); }
static string AttValue(string name, XmlNode node) { return(HandlersUtil.ExtractAttributeValue(name, node, true)); }
// A few methods to save some typing static string AttValue(string name, XmlNode node, bool optional) { return(HandlersUtil.ExtractAttributeValue(name, node, optional)); }
public virtual object Create(object parent, object configContext, XmlNode section) { HandlerFactoryConfiguration mapper; if (parent is HandlerFactoryConfiguration) { mapper = new HandlerFactoryConfiguration((HandlerFactoryConfiguration)parent); } else { mapper = new HandlerFactoryConfiguration(null); } if (section.Attributes != null && section.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", section); } XmlNodeList httpHandlers = section.ChildNodes; foreach (XmlNode child in httpHandlers) { XmlNodeType ntype = child.NodeType; if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment) { continue; } if (ntype != XmlNodeType.Element) { HandlersUtil.ThrowException("Only elements allowed", child); } string name = child.Name; if (name == "clear") { if (child.Attributes != null && child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } mapper.Clear(); continue; } string verb = HandlersUtil.ExtractAttributeValue("verb", child); string path = HandlersUtil.ExtractAttributeValue("path", child); string validateStr = HandlersUtil.ExtractAttributeValue("validate", child, true); bool validate; if (validateStr == null) { validate = true; } else { #if NET_2_0 validate = "true" == validateStr.ToLower(CultureInfo.InvariantCulture); if (!validate && "false" != validateStr.ToLower(CultureInfo.InvariantCulture)) #else validate = validateStr == "true"; if (!validate && validateStr != "false") #endif { HandlersUtil.ThrowException( "Invalid value for validate attribute.", child); } } if (name == "add") { string type = HandlersUtil.ExtractAttributeValue("type", child); if (child.Attributes != null && child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } mapper.Add(verb, path, type, validate); continue; } if (name == "remove") { if (child.Attributes != null && child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } if (validate && false == mapper.Remove(verb, path)) { HandlersUtil.ThrowException("There's no mapping to remove", child); } continue; } HandlersUtil.ThrowException("Unexpected element", child); } return(mapper); }
public virtual object Create(object parent, object configContext, XmlNode section) { ModulesConfiguration mapper; if (parent is ModulesConfiguration) { mapper = new ModulesConfiguration((ModulesConfiguration)parent); } else { mapper = new ModulesConfiguration(null); } if (section.Attributes != null && section.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", section); } XmlNodeList httpModules = section.ChildNodes; foreach (XmlNode child in httpModules) { XmlNodeType ntype = child.NodeType; if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment) { continue; } if (ntype != XmlNodeType.Element) { HandlersUtil.ThrowException("Only elements allowed", child); } string name = child.Name; if (name == "clear") { if (child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } mapper.Clear(); continue; } string name_attr = HandlersUtil.ExtractAttributeValue("name", child); if (name == "add") { string type = HandlersUtil.ExtractAttributeValue("type", child); if (child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } // FIXME: gotta remove this. Just here to make it work with my local config if (type.StartsWith("System.Web.Mobile")) { continue; } mapper.Add(name_attr, type); continue; } if (name == "remove") { if (child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } if (mapper.Remove(name_attr) == null) { HandlersUtil.ThrowException("Module not loaded", child); } continue; } HandlersUtil.ThrowException("Unrecognized element", child); } mapper.Add("DefaultAuthentication", typeof(DefaultAuthenticationModule)); return(mapper); }
public object Create(object parent, object configContext, XmlNode section) { PagesConfiguration config = new PagesConfiguration(parent); if (section.HasChildNodes) { HandlersUtil.ThrowException("No child nodes allowed here.", section); } string attvalue = AttValue("buffer", section); if (attvalue != null) { config.Buffer = GetBool("buffer", attvalue, section); } attvalue = AttValue("enableSessionState", section); if (attvalue != null) { switch (attvalue) { case "true": config.EnableSessionState = PagesEnableSessionState.True; break; case "ReadOnly": config.EnableSessionState = PagesEnableSessionState.ReadOnly; break; case "false": config.EnableSessionState = PagesEnableSessionState.False; break; default: HandlersUtil.ThrowException("The 'enableSessionState' attribute" + " is case sensitive and must be one of the following values:" + " false, true, ReadOnly.", section); break; } } attvalue = AttValue("enableViewState", section); if (attvalue != null) { config.EnableViewState = GetBool("enableViewState", attvalue, section); } attvalue = AttValue("enableViewStateMac", section); if (attvalue != null) { config.EnableViewStateMac = GetBool("enableViewStateMac", attvalue, section); } attvalue = AttValue("smartNavigation", section); if (attvalue != null) { config.SmartNavigation = GetBool("smartNavigation", attvalue, section); } attvalue = AttValue("autoEventWireup", section); if (attvalue != null) { config.AutoEventWireup = GetBool("autoEventWireup", attvalue, section); } attvalue = AttValue("validateRequest", section); if (attvalue != null) { config.ValidateRequest = GetBool("validateRequest", attvalue, section); } attvalue = AttValue("pageBaseType", section); if (attvalue != null) { string v = attvalue.Trim(); if (v.Length == 0) { HandlersUtil.ThrowException("pageBaseType is empty.", section); } config.PageBaseType = v; } attvalue = AttValue("userControlBaseType", section); if (attvalue != null) { string v = attvalue.Trim(); if (v.Length == 0) { HandlersUtil.ThrowException("userControlBaseType is empty.", section); } config.UserControlBaseType = v; } if (section.Attributes == null || section.Attributes.Count != 0) { HandlersUtil.ThrowException("Unknown attribute(s).", section); } return(config); }