[英]Remove IP Address from IP Security <ipSecurity> IIS8.0
我正在使用iis 8.0並嘗試從列表中刪除任何允許的/受限制的ip地址,屏幕快照已附加。 我已經通過以下鏈接使用remove變量。
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();
}
指導我我做錯了,如果是的話? 那這是什么。
我找到了從集合中刪除條目的方法。
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方法);
之后,它將完美運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.