【问题标题】:Bypass a rule in web.config file based on incoming IP address根据传入的 IP 地址绕过 web.config 文件中的规则
【发布时间】:2020-06-03 14:12:16
【问题描述】:

我已经尝试了 6 个小时的解决方案来解决这个问题,但在堆栈或微软的开发博客上都找不到任何东西。当通过内部调用访问网站时,我试图强制将所有外部调用的 HTTPS 重定向到我的网站,同时仍然访问 HTTP 站点,在这种情况下,通过使用 URL 栏中的 IP 地址 192.168.8.68浏览器。直到我们昨天安装了 SSL 证书并实施了以下重定向规则,这才完美运行:

<rule name="Redirect to HTTPS" patternSyntax="Wildcard" stopProcessing="true">
    <match url="*" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTPS}" pattern="OFF" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
</rule>

我想知道的是,如果传入的 IP 地址具有 192.168.8.* 的形式,我将如何绕过这个?在正则表达式中添加特定的 iP 会导致网站无法加载并显示“重定向错误过多”。为了解决这个问题,我已经查看了以下问题列表:

https://forums.iis.net/t/1166994.aspx?Rewrite+Redirection+for+only+external+users

IIS 7.5 redirect certain requests to other server using ip address

IIS | Block page specific url except for specific internal IP address

https://docs.secureauth.com/display/KBA/Use+URL+Rewrite+for+IP+Restrictions

Two instances of the same Website on IIS with different web.config (two different databases)

Single Website Directory / Multiple IIS Websites (Multiple web.config files)

【问题讨论】:

  • 至少第四个链接显示了如何添加IP地址相关条件,这回答了你的问题。当一些尝试没有奏效时,学习FRT调试,docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/…
  • 你是正确的 Lex,但我应该提到的是,由于重定向过多,该特定解决方案导致网站崩溃

标签: asp.net iis web-config iis-10


【解决方案1】:

您可以使用此规则绕过来自 ip 192.168.8.* 的请求。

<rule name="Redirect to HTTPS" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAny">
                        <add input="{HTTPS}" pattern="OFF" />
                        <add input="{REMOTE_ADDR}" pattern="192\.168\.8\.[0-9]+" negate="true" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" />
</rule>

【讨论】:

  • 嗨乔基斯。正如我在对该问题的评论中提到的,这会导致网站无法加载,因为涉及的重定向太多。
  • @ZGC1。对不起这是我的错。我忘记修改“logicalGrouping”,请将标志设置为
猜你喜欢
  • 2014-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-05
  • 2017-10-30
  • 2017-05-05
  • 2013-07-10
相关资源
最近更新 更多