internal static CustomErrors GetSettings(HttpContext context, bool canThrow) { CustomErrors ce = null; if (canThrow) { ce = (CustomErrors)context.GetConfig("system.web/customErrors"); } else { ce = (CustomErrors)context.GetLKGConfig("system.web/customErrors"); } if (ce == null) { if (_default == null) { _default = new CustomErrors(); } ce = _default; } return(ce); }
// // constructor used by config section handler // internal CustomErrors(XmlNode node, String basePath, CustomErrors parent) { _mode = CustomErrorsMode.Off; // inherit parent settings if (parent != null) { _mode = parent._mode; _defaultRedirect = parent._defaultRedirect; if (parent._codeRedirects != null) { _codeRedirects = new Hashtable(); for (IDictionaryEnumerator e = parent._codeRedirects.GetEnumerator(); e.MoveNext();) { _codeRedirects.Add(e.Key, e.Value); } } } // add current settings XmlNode a; String redirect = null; // get default and mode from the main tag HandlerBase.GetAndRemoveStringAttribute(node, "defaultRedirect", ref redirect); if (redirect != null) { _defaultRedirect = GetAbsoluteRedirect(redirect, basePath); } int iMode = 0; a = HandlerBase.GetAndRemoveEnumAttribute(node, "mode", typeof(CustomErrorsMode), ref iMode); if (a != null) { _mode = (CustomErrorsMode)iMode; } // report errors on bad attribures HandlerBase.CheckForUnrecognizedAttributes(node); // child tags foreach (XmlNode child in node.ChildNodes) { if (HandlerBase.IsIgnorableAlsoCheckForNonElement(child)) { continue; } int status = 0; // set when req. attr. is read // only <error> is allowed if (child.Name != "error") { HandlerBase.ThrowUnrecognizedElement(child); } // status code attribure a = HandlerBase.GetAndRemoveRequiredIntegerAttribute(child, "statusCode", ref status); if (status < 100 && status > 999) { throw new ConfigurationException( HttpRuntime.FormatResourceString(SR.Customerrors_invalid_statuscode), a); } // redirect attribure redirect = HandlerBase.RemoveRequiredAttribute(child, "redirect"); // errors on other attributes HandlerBase.CheckForUnrecognizedAttributes(child); // <error> tags contain no content HandlerBase.CheckForChildNodes(child); // remember if (_codeRedirects == null) { _codeRedirects = new Hashtable(); } _codeRedirects[status.ToString()] = GetAbsoluteRedirect(redirect, basePath); } }