我可以通过编程方式从我的ASP.NET应用程序向IIS7中的动态IP限制
发布时间:2020-12-16 07:07:27 所属栏目:asp.Net 来源:网络整理
导读:我正在创建一个基于论坛的网站,并希望阻止发布垃圾邮件或滥用的成员.我正在考虑使用HTTPModule来执行此操作,但我遇到了IIS7的动态IP限制扩展.我想知道是否可以从我的应用程序动态添加IP到扩展名? 此外,如果您有该扩展的经验,这将是伟大的.我,尤其是.有兴趣
我正在创建一个基于论坛的网站,并希望阻止发布垃圾邮件或滥用的成员.我正在考虑使用HTTPModule来执行此操作,但我遇到了IIS7的动态IP限制扩展.我想知道是否可以从我的应用程序动态添加IP到扩展名?
此外,如果您有该扩展的经验,这将是伟大的.我,尤其是.有兴趣知道它是否会影响高流量网站的性能. 谢谢 解决方法
我也对此感兴趣.
起初我使用IIS7中的UI将IP地址列入黑名单. 我确实看了上面提到的Rick Strahl链接,但在这里找到了一个很好的资源: http://www.iis.net/configreference/system.webserver/security/ipsecurity/add 该页面上的代码示例向您展示了如何使用C#执行操作.这是该网站的剪辑 using System; using System.Text; using Microsoft.Web.Administration; internal static class Sample { private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection ipSecuritySection = config.GetSection("system.webServer/security/ipSecurity","Default Web Site"); ConfigurationElementCollection ipSecurityCollection = ipSecuritySection.GetCollection(); ConfigurationElement addElement = ipSecurityCollection.CreateElement("add"); addElement["ipAddress"] = @"192.168.100.1"; addElement["allowed"] = false; ipSecurityCollection.Add(addElement); ConfigurationElement addElement1 = ipSecurityCollection.CreateElement("add"); addElement1["ipAddress"] = @"169.254.0.0"; addElement1["subnetMask"] = @"255.255.0.0"; addElement1["allowed"] = false; ipSecurityCollection.Add(addElement1); serverManager.CommitChanges(); } } } 要获取Microsoft.Web.Administration包,请在visual studio中转到工具 – > Nuget包管理器 – >包管理器控制台. 然后输入: Install-Package Microsoft.Web.Administration 执行相同任务的另一种方法是使用命令行和appcmd命令. 以下命令执行相同的操作: appcmd.exe set config "Default Web Site/SSM" -section:system.webServer/security/ipSecurity /+"[ipAddress='192.168.100.1',allowed='False']" /commit:apphost 并且可以使用以下代码从代码调用: string website = "Default Web Site/SSM"; string ipAddress = "192.168.100.1"; string allowDeny = "False"; string cmd = string.Format("%systemroot%system32inetsrvappcmd.exe set config "{0}" -section:system.webServer/security/ipSecurity /+"[ipAddress='{1}',allowed='{2}']" /commit:apphost",website,ipAddress,allowDeny); Process.Start(cmd); 上面的命令有效,但是如果你从C#调用它就会抱怨说“系统找不到指定Exception的文件”.要解决这个问题,你必须提供管理员用户名/密码. 这是功能: void BlacklistIP(string ipAddress) { string website = "Default Web Site/SSM"; string allowDeny = "False"; string domain = ""; string args = string.Format(" set config "{0}" -section:system.webServer/security/ipSecurity /+"[ipAddress='{1}',allowDeny); System.Security.SecureString password = new System.Security.SecureString(); password.AppendChar('y'); password.AppendChar('o'); password.AppendChar('u'); password.AppendChar('r'); password.AppendChar('p'); password.AppendChar('a'); password.AppendChar('s'); password.AppendChar('s'); password.AppendChar('w'); password.AppendChar('o'); password.AppendChar('r'); password.AppendChar('d'); Process.Start(@"C:windowsSystem32inetsrvappcmd.exe",args,"Administrator",password,domain); } Et Voila! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 如何在回发触发器中添加进度条
- asp.net – 如果我将ValidateRequest设置为false,这不是很危
- asp.net使用DataTable构造Json字符串的方法
- asp.net-mvc – json.net中哪个命名空间有JObject?
- ASP.NET线程敏捷 – 如何克服?
- asp.net – jQuery blackberry ajax问题
- asp.net-mvc – ASP.NET MVC单元测试控制器与HttpContext
- asp.net-mvc – ASP.NET MVC2和MemberShipProvider:它们如
- 我可以使用MiniProfiler来检测ASP.NET MVC WebApi网站吗?
- asp.net – 如何在文本框的点击事件上附加日历(全局)?
推荐文章
站长推荐
- ASP.NET MVC4异步聊天室
- asp.net-mvc – 有没有办法让RoutePrefix以可选参
- asp.net-mvc – ASP.NET MVC:将会话状态保存在类
- asp.net – 刷新大内容后的Kendo UI窗口
- asp.net – 为什么我的SiteMapPath在Firefox中有
- asp.net-web-api – ember-data:根据需要加载ha
- asp.net-mvc – ASP .NET MVC在视图之间存储大量
- 使用C#读取dbf行情文件
- asp.net-mvc – 使用IIS基本身份验证的OWIN身份验
- asp.net-mvc – 为什么HtmlHelpers需要这个HtmlH
热点阅读