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(); } } 该文章在 2021/5/11 18:35:01 编辑过 |
关键字查询
相关文章
正在查询... |