简体   繁体   English

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

[英]Remove IP Address from IP Security <ipSecurity> IIS8.0

I am using iis 8.0 and trying to remove any allowed/restricted ip address from the list, screen shot is attached. 我正在使用iis 8.0并尝试从列表中删除任何允许的/受限制的ip地址,屏幕快照已附加。 i have used the remove variable by following this link . 我已经通过以下链接使用remove变量。

IIS屏幕截图

        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();
            }

Guide me am i doing wrong, if yes? 指导我我做错了,如果是的话? then what is it. 那这是什么。

I have found the way to remove entry from the collection. 我找到了从集合中删除条目的方法。

 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();
        }

Every thing was alright only one thing was wrong in the 2nd last line. 一切都好,在倒数第二行只有一件事是错误的。

ipSecurityCollection.remove(addElement); ipSecurityCollection.remove(addElement方法);

Change it to 更改为

ipSecurityCollection.add(addElement); ipSecurityCollection.add(addElement方法);

After that it will work perfectly. 之后,它将完美运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM