首页 > 解决方案 > 在 IIS 上的 ASP.NET Core 应用程序中将 HTTPS 站点重定向到非 www

问题描述

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

标签: asp.net-coreasp.net-core-mvcasp.net-core-2.0

解决方案


使用 IIS URL Rewrite 模块将以下内容添加到您的 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中间件。


推荐阅读