Ejemplo n.º 1
0
        public CustomErrorsConfig(object parent, object context)
        {
            if (parent != null)
            {
                CustomErrorsConfig p = (CustomErrorsConfig)parent;
                mode            = p.mode;
                defaultRedirect = p.defaultRedirect;
                if (p.redirects != null && p.redirects.Count > 0)
                {
                    redirects = new Hashtable();
                    foreach (DictionaryEntry entry in p.redirects)
                    {
                        redirects [entry.Key] = entry.Value;
                    }
                }
            }

            configFilePath = Path.GetDirectoryName((string)context);
        }
		public object Create (object parent, object context, XmlNode section)
		{
			CustomErrorsConfig config = new CustomErrorsConfig (parent, context);
			
			string defaultRedirect = AttValue ("defaultRedirect", section);
			if (defaultRedirect != null)
				config.DefaultRedirect = defaultRedirect;

			string mode = AttValue ("mode", section);
			if (mode != null) {
				switch (mode) {
				case "On":
					config.Mode = CustomErrorMode.On;
					break;
				case "Off":
					config.Mode = CustomErrorMode.Off;
					break;
				case "RemoteOnly":
					config.Mode = CustomErrorMode.RemoteOnly;
					break;
				default:
					ThrowException ("Invalid value for 'mode': " + mode, section);
					break;
				}
			}
			
			if (section.Attributes != null && section.Attributes.Count != 0)
				ThrowException ("Unrecognized attribute", section);

			if (!section.HasChildNodes)
				return config;

			XmlNodeList children = section.ChildNodes;
			foreach (XmlNode child in children) {
				XmlNodeType ntype = child.NodeType;
				if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
					continue;

				if (ntype != XmlNodeType.Element)
					ThrowException ("Only elements allowed", child);

				if (child.Name != "error")
					ThrowException ("Unrecognized node: " + child.Name, child);

				string statusCode = AttValue ("statusCode", child, false, false);
				string redirect = AttValue ("redirect", child, false, false);
				int code = 0;
				try {
					code = Int32.Parse (statusCode);
				} catch {
					ThrowException ("Unable to parse 'statusCode': " + statusCode, child);
				}

				if (code < 100 || code >= 1000)
					ThrowException ("Invalid value for 'statusCode': " + code, child);

				config [code] = redirect;
			}

			return config;
		}
Ejemplo n.º 3
0
        public object Create(object parent, object context, XmlNode section)
        {
            CustomErrorsConfig config = new CustomErrorsConfig(parent, context);

            string defaultRedirect = AttValue("defaultRedirect", section);

            if (defaultRedirect != null)
            {
                config.DefaultRedirect = defaultRedirect;
            }

            string mode = AttValue("mode", section);

            if (mode != null)
            {
                switch (mode)
                {
                case "On":
                    config.Mode = CustomErrorMode.On;
                    break;

                case "Off":
                    config.Mode = CustomErrorMode.Off;
                    break;

                case "RemoteOnly":
                    config.Mode = CustomErrorMode.RemoteOnly;
                    break;

                default:
                    ThrowException("Invalid value for 'mode': " + mode, section);
                    break;
                }
            }

            if (section.Attributes != null && section.Attributes.Count != 0)
            {
                ThrowException("Unrecognized attribute", section);
            }

            if (!section.HasChildNodes)
            {
                return(config);
            }

            XmlNodeList children = section.ChildNodes;

            foreach (XmlNode child in children)
            {
                XmlNodeType ntype = child.NodeType;
                if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
                {
                    continue;
                }

                if (ntype != XmlNodeType.Element)
                {
                    ThrowException("Only elements allowed", child);
                }

                if (child.Name != "error")
                {
                    ThrowException("Unrecognized node: " + child.Name, child);
                }

                string statusCode = AttValue("statusCode", child, false, false);
                string redirect   = AttValue("redirect", child, false, false);
                int    code       = 0;
                try {
                    code = Int32.Parse(statusCode);
                } catch {
                    ThrowException("Unable to parse 'statusCode': " + statusCode, child);
                }

                if (code < 100 || code >= 1000)
                {
                    ThrowException("Invalid value for 'statusCode': " + code, child);
                }

                config [code] = redirect;
            }

            return(config);
        }