久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      如何使用IIS API禁用IP訪問

      IIS安裝欄目介紹如何使用IIS API禁用IP訪問

      如何使用IIS API禁用IP訪問

      免費推薦:IIS安裝

      這個類是基于 Microsoft.Web.Administration 寫的一個簡單封裝:
      PS: Microsoft.Web.Administration 可通過 Nuget 搜索安裝。

      public class IISAdministration {     private readonly ServerManager serverManager;     public IISAdministration()     {         serverManager = new ServerManager();     }      public IEnumerable<WorkerProcess> GetWorkerProcesses()     {         return serverManager.WorkerProcesses;     }      public IEnumerable<string> GetSiteNames()     {         foreach (var item in GetWorkerProcesses())         {             yield return item.AppPoolName;         }     }      public ConfigurationElementCollection GetIpSecurityCollection(string site)     {         return GetConfigurationElementCollection("system.webServer/security/ipSecurity", site);     }      public ConfigurationElementCollection GetConfigurationElementCollection(string sectionName, string site = "")     {         var config = serverManager.GetApplicationHostConfiguration();         ConfigurationSection section;         if (string.IsNullOrWhiteSpace(site))         {             section = config.GetSection(sectionName);         }         else         {             section = config.GetSection(sectionName, site);         }         return section.GetCollection();     }      public void CreateElement(ConfigurationElementCollection section, ConfigurationElement element)     {         section.Add(element);         serverManager.CommitChanges();     }      public void RemoveElement(ConfigurationElementCollection section, ConfigurationElement element)     {         section.Remove(element);         serverManager.CommitChanges();     }      public bool HasBlocked(string siteName, string ip)     {         var ipSecurityCollection = this.GetIpSecurityCollection(siteName);         for (int i = 0; i < ipSecurityCollection.Count; i++)         {             var element = ipSecurityCollection[i];             if ((string)element["ipAddress"] == ip)             {                 return true;             }         }         return false;     }      public void FreeIP(string siteName, string ip)     {         if (!HasBlocked(siteName, ip))         {             return;         }         var ipSecurityCollection = this.GetIpSecurityCollection(siteName);         for (int i = 0; i < ipSecurityCollection.Count; i++)         {             var element = ipSecurityCollection[i];             if ((string)element["ipAddress"] == ip)             {                 this.RemoveElement(ipSecurityCollection, element);                 break;             }         }     }      public void BlockIP(string siteName, string ip)     {         if (HasBlocked(siteName, ip))         {             return;         }         var ipSecurityCollection = this.GetIpSecurityCollection(siteName);         var element = ipSecurityCollection.CreateElement("add");         element["ipAddress"] = ip;         element["allowed"] = false;          ipSecurityCollection.Add(element);         serverManager.CommitChanges();     } }

      使用方法:

      var iisAdministration = new IISAdministration(); iisAdministration.BlockIP("", "192.0.0.1");

      注意:

      1. BlockIP第一個參數(shù)為站點名,如果空字符串,則直接添加到 IIS 根路徑下的IP屏蔽。
      2. 此方法會拋出異常,而且需要管理員權(quán)限才可執(zhí)行。

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號