[點晴永久免費OA]C#給IIS添加禁止IP限制
/// <summary> /// 給IIS添加禁止IP限制 /// 僅針對iis 7及以上版本 /// 首先需要引入Microsoft.Web.Administration.dll /// 該文件位置在windows2008的\Windows\System32\inetsrv目錄下 /// 注意:生成的EXE文件必須以管理員身份運行 /// </summary> /// <param name="ip"></param> private static void banIP(string ip) { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection ipSecuritySection = config.GetSection("system.webServer/security/ipSecurity"); ConfigurationElementCollection ipSecurityCollection = ipSecuritySection.GetCollection(); ConfigurationElement addElement = ipSecurityCollection.CreateElement("add"); addElement["ipAddress"] = ip; ipSecurityCollection.Add(addElement); serverManager.CommitChanges(); } }
該文章在 2019/9/4 23:31:51 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |