我正在使用iis 8.0并尝试从列表中删除任何允许/受限制的IP地址,附加了屏幕截图。我已经按照this link使用了删除变量。
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();
}
如果是的话,指导我做错了吗?那是什么。
答案 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方法);
之后它会完美运作。