首页 > 解决方案 > 如何忽略始终开启的 HTTPS Only Azure Appservice 自定义域设置

问题描述

我有一个作为 Azure AppService 运行的 ASP.Net Core 2.2 站点。作为配置的一部分,我有一个启用了仅 HTTPS设置的自定义域。

我还在我的 Appservice 上打开了Always on设置。

根据这篇文章 https://ruslany.net/2017/11/most-common-deployment-slot-swap-failures-and-how-to-fix-them/仅开启HTTPS时将忽略Always on设置结果,我的网站总是在第一次通话时冷启动。

根据同一篇文章,可以在 web.config 中设置规则条件,如果处理了 {warmup_request} ,则不处理重定向到 HTTPS规则。

但是,我的HTTPS 仅设置在 Azure 中的自定义域上,而不是 web.config 中的规则。

我在 startup.cs 中使用以下代码设置 RouteOptions:

services.Configure<RouteOptions>(options =>
{
    options.LowercaseUrls = true;
});

并相信规则条件也可以在这里完成,options.ConstraintMap()但我不确定表示以下内容所需的语法或方法:

  <match url="(.*)" />
  <conditions>
    <add input="{WARMUP_REQUEST}" pattern="1" negate="true" />
    <add input="{REMOTE_ADDR}" pattern="^100?\." negate="true" />
    <add input="{HTTPS}" pattern="^OFF$" />
  </conditions>
  <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>

任何有关如何执行此操作的帮助将不胜感激

谢谢

标签: asp.net-corehttpsazure-web-app-serviceapp-startupapplication-warmup

解决方案


从撰写本文开始,“仅 https”已添加为应用服务的内置功能,因此不再需要使用此重写规则。

至于如何最小化您的应用程序的冷启动 - 您可能需要考虑将 appinit 配置添加到 web.config,如App Service Warm-Up Demystified中所述


推荐阅读