尝试通过IP地址保护文件夹中的所有aspx文件

时间:2014-04-21 19:48:16

标签: asp.net security

我希望保护文件夹~/Secure/中的所有aspx文件安全,以便特定的IP地址可以访问文件夹的aspx文件。我将以下web.config文件添加到该文件夹​​,希望它添加到父web.config

<configuration>
  <system.webServer>
    <security>
      <ipSecurity allowUnlisted="false">
        <clear/>
        <add ipAddress="192.168.100.1" />
        <add ipAddress="169.254.0.0" subnetMask="255.255.0.0" />
      </ipSecurity>
    </security>
  </system.webServer>
</configuration>

问题是当我尝试访问文件夹中的任何aspx页面时出现此错误:

This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false"

让这个想法发生怎么办?我只想将一个web.config文件包含到文件夹中,并强制执行IP地址授权。我喜欢这个想法,因为它只是无代码和配置。

2 个答案:

答案 0 :(得分:1)

您不能仅在网站web.config中执行此操作。

如果可以使用IIS管理器: 打开IIS管理器,找到该站点,单击要保护的文件夹,然后单击“IP地址和域重建”。

同时点击&#34;编辑功能设置&#34;在右侧的动作面板&#34;为未指定的客户指定操作(即拒绝带有禁止,或者只是拒绝找不到)。

这将为您生成正确的配置。

答案 1 :(得分:0)

在您的根web.config中使用location element: -

<location path="Secure">
  <system.webServer>
    <security>
      <ipSecurity allowUnlisted="false">
        <clear/>
        <add ipAddress="192.168.100.1" />
        <add ipAddress="169.254.0.0" subnetMask="255.255.0.0" />
      </ipSecurity>
    </security>
  </system.webServer>
</location>