C#給IIS添加禁止IP限制
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
/// <summary> /// 給IIS添加禁止IP限制 /// 僅針對(duì)iis 7及以上版本 /// 首先需要引入Microsoft.Web.Administration.dll /// 該文件位置在windows2008的\Windows\System32\inetsrv目錄下 /// 注意:生成的EXE文件必須以管理員身份運(yùn)行 /// </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(); } } 該文章在 2021/5/11 18:35:01 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |