【问题标题】:Allow "localhost" to run in iisexpress when web.config contains ipSecurity permissions当 web.config 包含 ipSecurity 权限时,允许“localhost”在 iisexpress 中运行
【发布时间】:2021-10-26 11:46:05
【问题描述】:

我刚刚将它添加到我的 web.config 中:

<security>
  <ipSecurity allowUnlisted="false">
    <!-- The following IP addresses are granted access, all else denied -->
    <add allowed="true" ipAddress="123.123.105.0" subnetMask="255.255.255.0" />
    <add allowed="true" ipAddress="123.123.100.0" subnetMask="255.255.255.0" />
  </ipSecurity>
</security>

完全按预期工作,仅在特定 IP 范围内。但是,现在当我通过 iisExpress 在 localhost 上在 Visual Studio 中对此进行测试时,它当然会给我带来问题。这是我收到的 500.19 错误:

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".

我已经在服务面板中的本地机器上设置了 IPSecurity,因此它已启用,并且我在 ipSecurity 块中使用了一些选项,例如将“localhost”添加为 domainName 值 - 但可惜没有运气。 ....帮助我 StackOverflow,你是我唯一的希望! ;)

【问题讨论】:

  • 我也遇到了这个问题,好像也找不到解决办法

标签: web-config localhost visual-studio-2013 iis-express


【解决方案1】:

我刚刚遇到了同样的情况。我搜索了一下,发现您所要做的就是编辑此处找到的 IIS Express 的 applicationhost.config 文件:

%userprofile%\Documents\IISExpress\config\applicationhost.config

打开它并查找 system.webServer 部分内的 ipSecurity 部分并将 overrideModeDefault 从“拒绝”更改为“允许”。您无需从 Windows 功能中添加 IIS IP 安全

<sectionGroup name="system.webServer">
  <sectionGroup name="security">
    ...
    <section name="ipSecurity" overrideModeDefault="Allow" />
    ...
  </sectionGroup>
</sectionGroup>

希望这会有所帮助!

注意:对于 Windows 10Visual Studio 2015(或更高版本),请注意 ApplicationHost.config 文件已重新定位到 .vs\项目文件夹层次结构中的 config 文件夹

【讨论】:

  • 这样做了,它似乎让我更接近了 - 现在我收到以下错误:HTTP 错误 403.503 - 禁止您无权查看此目录或页面。
  • 403.502和503代码与IIS中的IP限制模块有关。我相信你可能会把自己挡在外面。 (forums.iis.net/p/1210696/…) 编辑:哦等等!您必须将 localhost 添加到您的允许列表中。
  • 一定有更多的东西。我已经在两台不同的 PC 上尝试过这个 - 但它不起作用。我仍然收到相同的错误消息“此配置部分不能在此路径上使用。当...时发生这种情况”。
  • 查看这个答案 - stackoverflow.com/a/33710459/261690 - 在 VS2015 下,applicationhost.config 现在位于项目特定的位置。
  • 在文件中查找此部分:sectionGroup name="system.webServer"
【解决方案2】:

将 127.0.0.1 添加到允许的 ip,如下所示:

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

感谢@AbeyMarquez,我认为您的评论值得更多关注,因为它解决了我的问题。谢谢!

【讨论】:

    猜你喜欢
    • 2017-09-23
    • 1970-01-01
    • 2016-01-02
    • 2019-03-01
    • 2018-10-28
    • 2012-01-26
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    相关资源
    最近更新 更多