为许多位置添加IP安全性

时间:2014-11-12 11:55:05

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

如何为多个位置添加多个规则

我有一个MVC应用程序我在Web.Config中添加了以下部分:

  <system.webServer>
     <security>
       <ipSecurity allowUnlisted="false">
          <clear /> 

       <add ipAddress="127.0.0.1" allowed="true" />

       <add ipAddress="41.111.32.153" allowed="true" />
       </ipSecurity>
    </security>
  <system.webServer>

现在我想添加另一个安全规则以允许访问某些ips的主页,我尝试过将此部分添加到基础类似下面:

<location path="Home">
  <system.webServer>
    <security>
      <ipSecurity allowUnlisted="false">
        <clear /> 
        <add ipAddress="44.244.6.162" allowed="true" />
        <add ipAddress="44.244.6.163" allowed="true" />
      </ipSecurity>
    </security>
  </system.webServer>
</location>

我也试过<location path="Home" allowOverride="true">,但它也不起作用!

你能告诉我我应该写些什么来和我一起工作吗?

1 个答案:

答案 0 :(得分:0)

为什么你不能使用授权过滤器?使用此方法,您可以在运行时添加ip配置,也可以使用SQL表,并在每个操作中执行授权。