Пример #1
0
        public static void AddQueryStringRestriction(IisSite info, QueryStringRestriction queryRule)
        {
            using (var serverManager = ServerManager.OpenRemote(info.Hostname))
            {
                var conf = serverManager.GetWebConfiguration(info.Sitename);

                // Add URL restrictions
                var reqFilterSec             = conf.GetSection("system.webServer/security/requestFiltering");
                var denyQueryStringSequences = reqFilterSec.GetCollection("denyQueryStringSequences");

                var addElement = denyQueryStringSequences.CreateElement("add");
                addElement["sequence"] = queryRule.Sequence;
                denyQueryStringSequences.Add(addElement);

                // Save changes
                serverManager.CommitChanges();
            }
        }
Пример #2
0
        public static void RemoveQueryStringRestriction(IisSite info, QueryStringRestriction queryRule)
        {
            using (var serverManager = ServerManager.OpenRemote(info.Hostname))
            {
                var conf = serverManager.GetWebConfiguration(info.Sitename);

                // Add URL restrictions
                var reqFilterSec             = conf.GetSection("system.webServer/security/requestFiltering");
                var denyQueryStringSequences = reqFilterSec.GetCollection("denyQueryStringSequences");

                foreach (var element in denyQueryStringSequences.Where(element => (string)element.Attributes["sequence"].Value == queryRule.Sequence))
                {
                    denyQueryStringSequences.Remove(element);
                    break;
                }

                // Save changes
                serverManager.CommitChanges();
            }
        }