管理站点IP策略_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > 管理站点IP策略

管理站点IP策略

 2013/12/9 21:26:02  ascrat  博客园  我要评论(0)
  • 摘要:修改站点IP策略的代码usingSystem;usingSystem.Text;usingMicrosoft.Web.Administration;internalstaticclassSample{privatestaticvoidMain(){using(ServerManagerserverManager=newServerManager()){Configurationconfig=serverManager.GetApplicationHostConfiguration()
  • 标签:

 

修改站点IP策略的代码

 

class="brush:csharp;gutter:true;">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();
      }
   }
}

  

或者修改Web.Config:

 

<location path="Default Web Site">
   <system.webServer>
      <security>
         <ipSecurity>
            <add ipAddress="192.168.100.1" />
            <add ipAddress="169.254.0.0" subnetMask="255.255.0.0" />
         </ipSecurity>
      </security>
   </system.webServer>
</location>

  

 来源:http://www.iis.net/configreference/system.webserver/security/ipsecurity/add

 

  • 相关文章
发表评论
用户名: 匿名