C#給Windows服務(wù)器的IIS添加禁止IP限制
當前位置:點晴教程→知識管理交流
→『 技術(shù)文檔交流 』
/// <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();
}
}
該文章在 2022/6/11 14:50:18 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |