2

I ran "Diagnose and solve problems" on Azure dashboard inside one of the app services, and then I got this critical risk alert: "Application evaluated unhealthy due to redirection.".

Recommended actions is:

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.

I already enable 'HTTPs Only' as suggested on point (a), but I don't know how to do point (b). How to 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 ?

Currently, I enable Health Check and set the Health Check path to /.

Thanks before for any help.

enter image description here

Dika
  • 2,213
  • 4
  • 33
  • 49
  • What have you tried? The relevant code of `Use HealthChecks` is best updated in the post. – Jason Pan Jan 11 '21 at 09:00
  • [Health checks in ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-5.0) – Jason Pan Jan 11 '21 at 09:00
  • @JasonPan thanks for the comments, really glad someone responded. I only tried to enable the health check, set the path to `/`, and set load balancing time to 2 minutes. you can see here: https://drive.google.com/file/d/1zedMyE0jHWMsb9mofvJ-FaBFpP0ZdNT2/view?usp=sharing . this is an app service for a wordpress site, but I use web.config instead of .htaccess. I guess I need to update the web.config. Please see my other question at https://stackoverflow.com/questions/65639409/how-to-add-rewrite-rule-to-azure-web-config-so-that-certain-requests-are-not-red – Dika Jan 11 '21 at 09:54

1 Answers1

0

I download offical sample, and make some changes in code, hope it useful to you.

Sample Code --- .net core 3.X(HealthChecksSample)

Method 1.

Because the code is in .net core, I first recommend configuring rewrite in 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.");
        });
    });
}

It works for me, both in local and azure web app.

enter image description here

I will add Method 2 in your another post.

Jason Pan
  • 15,263
  • 1
  • 14
  • 29