Beispiel #1
0
        public static void AddHeaderLimit(HeaderLimit headerLimit, RequestFilteringSection section)
        {
            if (headerLimit == null)
            {
                throw new ArgumentNullException("headerLimit");
            }
            if (headerLimit.Header == null)
            {
                throw new ArgumentNullException("headerLimit.Header");
            }

            HeaderLimitCollection collection = section.RequestLimits.HeaderLimits;

            if (collection.Any(h => h.Header.Equals(headerLimit.Header)))
            {
                throw new AlreadyExistsException("headerLimit");
            }

            try {
                collection.Add(headerLimit);
            }
            catch (FileLoadException e) {
                throw new LockedException(section.SectionPath, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }
        }
Beispiel #2
0
        public static void DeleteHeaderLimit(HeaderLimit headerLimit, RequestFilteringSection section)
        {
            if (headerLimit == null)
            {
                return;
            }

            HeaderLimitCollection collection = section.RequestLimits.HeaderLimits;

            // To utilize the remove functionality we must pull the element directly from the collection
            headerLimit = collection.FirstOrDefault(h => h.Header.Equals(headerLimit.Header));

            if (headerLimit != null)
            {
                try {
                    collection.Remove(headerLimit);
                }
                catch (FileLoadException e) {
                    throw new LockedException(section.SectionPath, e);
                }
                catch (DirectoryNotFoundException e) {
                    throw new ConfigScopeNotFoundException(e);
                }
            }
        }