【问题标题】:Trying to secure all aspx files in a folder secure by IP address试图通过 IP 地址保护文件夹中的所有 aspx 文件
【发布时间】:2023-03-05 12:14:01
【问题描述】:

我喜欢保护 ~/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 地址授权。我喜欢这个想法,因为它没有代码和配置。

【问题讨论】:

  • 在这方面需要任何额外帮助吗?如果我的回答中缺少任何内容,请告诉我。

标签: asp.net security


【解决方案1】:

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

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

还可以单击右侧“操作”面板中的“编辑功能设置”,为未指定的客户端指定操作(即“禁止使用拒绝”,或简单地“未找到拒绝”)。

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

【讨论】:

  • 我真的希望可以做到这一点,因为我可以将 web.config 作为我的应用程序源的一部分进行维护。我们知道这个配置部分被锁定在哪里吗?在 machine.config 中吗?
【解决方案2】:

在你的根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>

【讨论】:

  • 我将它添加到应用程序根 web.config 并收到此错误:此配置部分不能在此路径中使用。当该部分锁定在父级别时会发生这种情况。默认情况下锁定 (overrideModeDefault="Deny"),或者由具有 overrideMode="Deny" 或旧版 allowOverride="false" 的位置标记显式设置。
  • @AllanXu 确保删除子文件夹中的web.configsuggested 您可能还需要启用 IP 和域限制 (Control Panel &gt; Programs and Features &gt; Turn Windows features on or off &gt; Internet Information Services &gt; World Wide Web Services &gt; Security and tick IP Security)。
  • 我已经删除了子文件夹中的 web.config。我按照这里的所有说明进行操作:iis.net/configreference/system.webserver/security/ipsecurity 仍然是同样的错误。我在 Windows 2012 下运行。
  • 你有没有机会让它在你的环境中工作?
猜你喜欢
  • 2014-05-28
  • 1970-01-01
  • 1970-01-01
  • 2015-06-02
  • 2021-12-21
  • 1970-01-01
  • 2014-12-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多