【问题标题】:How to redirect url to ssl url on localhost in web.confg如何在 web.config 中将 url 重定向到 localhost 上的 ssl url
【发布时间】:2020-12-11 01:20:04
【问题描述】:

localhost:5011 是 url,localhost:44330 是 SSL url。我想在我的 web.config 中将 http://localhost:5011 重定向到 https://localhost:44330。我找到了这个规则,但它没有按我的意愿工作:

<rule name="Redirect local requests to https" stopProcessing="true">
    <match url="(localhost:5011*)" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions>
    <action type="Redirect" url="https://localhost:44330/" redirectType="Permanent" appendQueryString="true" />
</rule>   

这将重定向到 https://localhost:5011。我该如何解决这个问题?

【问题讨论】:

标签: asp.net xml iis https web-config


【解决方案1】:

我认为你的规则不会重定向因为

如果需要将http://localhost:5011重定向到https://localhost:44330,请试试这个规则

 <rule name="Redirect local requests to https" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTPS}" pattern="off" />
                        <add input="{HTTP_HOST}" pattern="localhost" />
                        <add input="{SERVER_PORT}" pattern="^5011$" />
    </conditions>
    <action type="Redirect" url="https://localhost:44330/" redirectType="Permanent" appendQueryString="true" />
</rule>   

II 不应该将 http://localhost:5011 重定向到 https://localhost:5011,所以请检查您是否有其他重写规则或您的应用程序正在做同样的工作。

【讨论】:

  • 此解决方案在每个重定向到一页的请求中缺少一个点。例如,如果请求localhost:5011/mypage,那么它会重定向到localhost:44330。为了解决这个问题,我将 {REQUEST_URI} 添加到重定向 url。
猜你喜欢
  • 2012-08-27
  • 2017-06-19
  • 1970-01-01
  • 2017-12-30
  • 1970-01-01
  • 1970-01-01
  • 2010-10-18
  • 1970-01-01
  • 2015-09-20
相关资源
最近更新 更多