Example #1
0
		void LoadWebConfig(string path)
		{
			try
			{
				httpHandlers.Clear();
				configFile = new XmlDocument();
				configFile.Load(path);

				XmlNode handlersNode = configFile.DocumentElement.SelectSingleNode("/configuration/system.web/httpHandlers");
				if(handlersNode == null)
					return;
				
				lock(httpHandlers)
				{
					foreach(XmlNode node in handlersNode)
					{
						switch(node.Name)
						{
							case "add":
							{
								if(node.Attributes["verb"] == null)
									break;
								if(node.Attributes["path"] == null)
									break;
								if(node.Attributes["type"] == null)
									break;

								bool validate = false;
								
								try
								{
									if(node.Attributes["validate"] != null)
										validate = bool.Parse(node.Attributes["validate"].Value);
								}
								catch(FormatException)
								{
									validate = false;
								}

								HttpHandler handler = new HttpHandler(node.Attributes["verb"].Value, node.Attributes["path"].Value, node.Attributes["type"].Value, validate);
								httpHandlers.Remove(handler);
								httpHandlers.Add(handler);

								break;
							}
							case "remove":
							{
								if(node.Attributes["verb"] == null)
									break;
								if(node.Attributes["path"] == null)
									break;

								HttpHandler handler = new HttpHandler(node.Attributes["verb"].Value, node.Attributes["path"].Value, null, false);
								httpHandlers.Remove(handler);

								break;
							}
							case "clear":
							{
								httpHandlers.Clear();

								break;
							}
						}
					}
				}
			}
			catch(Exception)
			{
				httpHandlers.Clear();
				configFile = null;
			}
		}
        void LoadWebConfig(string path)
        {
            try
            {
                httpHandlers.Clear();
                configFile = new XmlDocument();
                configFile.Load(path);

                XmlNode handlersNode = configFile.DocumentElement.SelectSingleNode("/configuration/system.web/httpHandlers");
                if (handlersNode == null)
                {
                    return;
                }

                lock (httpHandlers)
                {
                    foreach (XmlNode node in handlersNode)
                    {
                        switch (node.Name)
                        {
                        case "add":
                        {
                            if (node.Attributes["verb"] == null)
                            {
                                break;
                            }
                            if (node.Attributes["path"] == null)
                            {
                                break;
                            }
                            if (node.Attributes["type"] == null)
                            {
                                break;
                            }

                            bool validate = false;

                            try
                            {
                                if (node.Attributes["validate"] != null)
                                {
                                    validate = bool.Parse(node.Attributes["validate"].Value);
                                }
                            }
                            catch (FormatException)
                            {
                                validate = false;
                            }

                            HttpHandler handler = new HttpHandler(node.Attributes["verb"].Value, node.Attributes["path"].Value, node.Attributes["type"].Value, validate);
                            httpHandlers.Remove(handler);
                            httpHandlers.Add(handler);

                            break;
                        }

                        case "remove":
                        {
                            if (node.Attributes["verb"] == null)
                            {
                                break;
                            }
                            if (node.Attributes["path"] == null)
                            {
                                break;
                            }

                            HttpHandler handler = new HttpHandler(node.Attributes["verb"].Value, node.Attributes["path"].Value, null, false);
                            httpHandlers.Remove(handler);

                            break;
                        }

                        case "clear":
                        {
                            httpHandlers.Clear();

                            break;
                        }
                        }
                    }
                }
            }
            catch (Exception)
            {
                httpHandlers.Clear();
                configFile = null;
            }
        }