asp.net-core - 我按照文档中的建议配置了 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
解决方案
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 应用程序。
推荐阅读
- mysql - MySql DATE_FORMAT 未按预期工作
- angular - 自定义验证器不显示角度错误
- php - Symfony - Doctrine - Repository - WHERE 值可能为空或不为空
- javascript - 如何提交 Rackspace API 电子邮件添加阻止列表请求
- python - 根据阈值减少列表中元组的数量
- python-3.x - 我无法在 Python 中使用 speech_recognition 查看我的文本输出
- wordpress - 根据当前用户的帖子 ID 显示 acf 自定义字段(wordpress)
- python-3.x - 马尔可夫链蒙特卡罗模拟的修复数据
- java - 构建 jar 文件时出现 NoClassDefFoundError
- wordpress - 在 wordpress 的 WP-content 中生成多个图像