2017-05-25 67 views
2

我正在使用iis 8.0並試圖從列表中刪除任何允許/限制的IP地址,附上屏幕截圖。我通過以下this link使用了刪除變量。從IP安全刪除IP地址<ipSecurity> IIS8.0

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

指導我我做錯了什麼,如果是?那這是什麼。

回答

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方法);

之後,它會完美的工作。