首页 > 解决方案 > 我按照文档中的建议配置了 IIS ApplicationInitialization addinitializationPage='/warm-up'

问题描述

我按照文档中的建议配置了 IIS ApplicationInitialization,添加了 initializationPage='/warm-up'。

我在我的应用程序上实现了一个 /warm-up 端点,将其部署到暂存槽和生产槽。

当应用程序启动/重新启动/交换时,不会调用端点,因为我在日志中看不到它。当我手动点击端点时,它工作正常!

What I'm trying to achieve is:

当我启动/重新启动/交换我的应用程序时,我希望调用一个页面(/warm-up)以预加载应用程序所以来自真实客户端的第一次调用不必受到应用程序加载时间的影响

Currently,  I implemented a service that runs when the app starts (IStartupfilter)

但是在第一个请求到达服务器之前,应用程序(因此过滤器)没有运行!

So I want to hit the server instance as soon as possible with appInit

We have more than 5 instances at some time of the day

标签: asp.net-coreazure-app-service-envrmnt

解决方案


initializationPage是 IIS 的东西,它不会帮助您在第一个请求命中之前启动 ASP.NET Core 应用程序。

相反,您需要为 ASP.NET Core 配置应用程序初始化模块。根据此文档,您将需要启用 IIS 应用程序初始化模块(如果可以配置,您可能已经这样做了initializationPage),然后修改生成web.config的以将applicationInitialization节点包含到 webServer 部分:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\MyApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />

      <applicationInitialization doAppInitAfterRestart="true" />
    </system.webServer>
  </location>
</configuration>

这应该会在 IIS 网站启动后立即启动 ASP.NET Core 应用程序,因此应该没有延迟。然后,您将不需要初始化页面,只需在主机启动时初始化 ASP.NET Core 应用程序。


推荐阅读