2

我在其中一个应用服务内的 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”,但我不知道如何执行 (b) 点。如何修改应用程序逻辑/广告 URL 重写规则,以便来自用户代理的请求 - ReadyForRequest/1.0+(HealthCheck)&HealthCheck/1.0不被重定向?

目前,我启用了健康检查并将健康检查路径设置为/.

在此之前感谢您的帮助。

在此处输入图像描述

4

1 回答 1

0

我下载了官方示例,并对代码进行了一些更改,希望对您有用。

示例代码 --- .net core 3.X(HealthChecksSample)

方法一。

因为代码在.net core中,所以我首先推荐在.net中配置rewrite Startup.cs

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在你的另一篇文章中添加。

于 2021-01-12T02:50:20.547 回答