asp.net阻止IP范围

时间:2015-09-03 11:29:44

标签: asp.net asp.net-mvc web-config

我想在asp.net mvc网站上做一个IP范围块,我在web.config中有这个:

  <system.webServer>
<security>
  <ipSecurity allowUnlisted="false">
    <add ipAddress="1.1.1.1" subnetMask="255.255.0.0" />
    <add ipAddress="2.2.2.2" subnetMask="255.255.0.0" />
  </ipSecurity>
</security>


<handlers>
  ...
</handlers>

但是当我尝试运行该页面时,我得到了这个

IIS Error

我该怎么做ip范围块?

2 个答案:

答案 0 :(得分:0)

听起来您需要在本地IIS上安装IP Security模块(当您上线时需要安装服务器)。该行的错误有问题:

<ipSecurity allowUnlisted="false"> 

哪个是正确的,虽然目前allowUnlisted设置为false,但您目前只允许在您的规则中指定的IP,并且看起来您想要相反,所以将其设置为true

答案 1 :(得分:0)

来自documentation

  

首先,创建一个在角色启动时运行的命令文件   解锁ApplicationHost.config文件的ipSecurity部分。   在Web角色的根级别创建一个名为startup的新文件夹   并在此文件夹中创建名为startup.cmd的批处理文件。组   此文件的属性为“始终复制”以确保它将是   展开。

     

将以下代码添加到startup.cmd文件中:

%windir%\system32\inetsrv\AppCmd.exe unlock config -section:system.webServer/security/ipSecurity
     

接下来,打开Web角色项目中的ServiceDefinition.csdef文件   并添加以下元素:

<Startup>
   <Task commandLine=”startup\startup.cmd” executionContext=”elevated” />
</Startup>
     

这会导致每次在web上运行startup.cmd批处理文件   角色初始化,确保所需的ipSecurity部分   解锁。

如果您没有加载模块。

然后,如果您想要黑名单,则应将<ipSecurity allowUnlisted="false">更改为<ipSecurity allowUnlisted="true">

关于它是如何工作的非常好的文章could be found here

相关问题