我在其中一个应用程序服务中的Azure仪表板上运行了“诊断和解决问题”,然后我收到了这个关键风险警报:“由于重定向,应用程序评估不健康。”
建议的操作是:
If the application has HTTP to HTTPS redirectoin, consider one of the following solutions.
a. Enable 'HTTPs Only' from the TLS/SSL settings blade for the respective App Service. This will force health check pings to over 443.
b. Modify the Application logic/ad a URL Rewrite rule so that requests from the user agents – ReadyForRequest/1.0+(HealthCheck) & HealthCheck/1.0 are not redirected.我已经按照第(a)点的建议启用了'HTTPs Only‘,但我不知道如何做第(b)点。如何修改应用程序逻辑/ are重写规则,使来自用户代理- ReadyForRequest/1.0+(HealthCheck) & HealthCheck/1.0的请求不会被重定向?
目前,我启用了健康检查,并将健康检查路径设置为/。
谢谢你之前的帮助。

发布于 2021-01-12 10:50:21
我下载了offical示例,并对代码做了一些修改,希望对你有用。
示例代码- .net core 3.X(HealthChecksSample)
方法1。
因为代码在.net核心中,所以我建议首先在中配置重写
public void Configure(IApplicationBuilder app)
{
app.UseHealthChecks("/");
app.UseRouting();
app.MapWhen(
ctx => ctx.Request.Path.StartsWithSegments("/"),
appBuilder =>
{
appBuilder.UseMiddleware<HealthCheckMiddleware>();
}
);
app.UseEndpoints(endpoints =>
{
endpoints.MapHealthChecks("/");
endpoints.MapGet("/{**path}", async context =>
{
await context.Response.WriteAsync(
"Navigate to /health to see the health status.");
});
});
}无论是在本地还是在azure web应用程序中,它都适用于我。

我会在你的另一篇文章中添加Method 2。
https://stackoverflow.com/questions/65627278
复制相似问题