从IP安全<ipsecurity> IIS8.0中删除IP地址

时间:2017-05-25 13:31:04

标签: iis

我正在使用iis 8.0并尝试从列表中删除任何允许/受限制的IP地址,附加了屏幕截图。我已经按照this link使用了删除变量。

IIS Screen Shot

        var websiteName = "abc.com";
            using (var serverManager = new ServerManager())
            {
                var config = serverManager.GetApplicationHostConfiguration();
                var ipSecuritySection = config.GetSection("system.webServer/security/ipSecurity", websiteName);
                var ipSecurityCollection = ipSecuritySection.GetCollection();

                var addElement = ipSecurityCollection.CreateElement("remove");
                addElement["ipAddress"] = ipAddress;
                ipSecurityCollection.Remove(addElement);
                serverManager.CommitChanges();
            }

如果是的话,指导我做错了吗?那是什么。

1 个答案:

答案 0 :(得分:3)

我找到了从集合中删除条目的方法。

 var websiteName = "abc.com";
        using (var serverManager = new ServerManager())
        {
            var config = serverManager.GetApplicationHostConfiguration();
            var ipSecuritySection = config.GetSection("system.webServer/security/ipSecurity", websiteName);
            var ipSecurityCollection = ipSecuritySection.GetCollection();

            var addElement = ipSecurityCollection.CreateElement("remove");
            addElement["ipAddress"] = ipAddress;
            ipSecurityCollection.add(addElement);
            serverManager.CommitChanges();
        }

在最后一行中,每件事情都没有问题。

  

ipSecurityCollection.remove(addElement方法);

将其更改为

  

ipSecurityCollection.add(addElement方法);

之后它会完美运作。