在IIS的ASP.NET Core应用程序中将HTTPS站点重定向到非www

时间:2018-07-05 11:23:59

标签: asp.net-core asp.net-core-mvc asp.net-core-2.0

我不想更改我的代码 是否有通过IIS将HTTPS站点重定向到ASP.NET Core应用程序中的非www的任何解决方案? IIS上有什么解决方案吗?

1 个答案:

答案 0 :(得分:0)

使用IIS URL重写模块将以下内容添加到您的web.config:

<system.webServer>
  <rewrite>
    <rules>
      <rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
        <match url="(.*)" /> 
        <conditions> 
          <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        </conditions> 
        <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
      </rule> 
    </rules>
  </rewrite>
</system.webServer>

如果使用ASP.NET Core 2.1,则可以使用UseHttpsRedirection中间件。