Example #1
0
        public static void AddRule(Rule rule, RequestFilteringSection section)
        {
            if (rule == null)
            {
                throw new ArgumentNullException("rule");
            }
            if (rule.Name == null)
            {
                throw new ArgumentNullException("rule.Name");
            }

            FilteringRuleCollection collection = section.FilteringRules;

            if (collection.Any(r => r.Name.Equals(rule.Name)))
            {
                throw new AlreadyExistsException("rule");
            }

            try {
                collection.Add(rule);
            }
            catch (FileLoadException e) {
                throw new LockedException(section.SectionPath, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }
        }