Home > Net >  Healthchecks UI not showing, resulting in a blankpage [.NET 6]
Healthchecks UI not showing, resulting in a blankpage [.NET 6]

Time:12-03

What happened: The default Healthchecks UI page displays a blank page.

What you expected to happen: To properly see the default Healthchecks UI page.

How to reproduce it (as minimally and precisely as possible): In Program.cs, use app.MapHealthChecks() and app.MapHealthChecksUI()

Source code sample: Below is the Program.cs file.

using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using MonitoringApi.HealthChecks;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddHealthChecks()
    .AddCheck<RandomHealthCheck>("Site Health Check")
    .AddCheck<RandomHealthCheck>("Database Health Check");

builder.Services.AddHealthChecksUI(opts =>
{
    opts.AddHealthCheckEndpoint("api", "/health");
    opts.SetEvaluationTimeInSeconds(5);
    opts.SetMinimumSecondsBetweenFailureNotifications(10);
}).AddInMemoryStorage();

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();
app.MapHealthChecks("/health", new HealthCheckOptions
{
    ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
app.MapHealthChecksUI();

app.Run();

Anything else we need to know?: Possibly occuring if you have installed Watchdogs before.

Environment:

  • .NET Core version 6
  • Healthchecks version 6.0.5
  • Operative system: Windows 10

CodePudding user response:

The solution was by replacing in Program.cs, the app.MapHealtchChecks() and app.MapHealthChecksUI() with app.UseHealthChecks() and app.UseHealthChecksUI() as seen below.

using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using MonitoringApi.HealthChecks;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddHealthChecks()
        .AddCheck<RandomHealthCheck>("Site Health Check")
        .AddCheck<RandomHealthCheck>("Database Health Check");

builder.Services.AddHealthChecksUI(opts =>
{
    opts.AddHealthCheckEndpoint("api","/health");
    opts.SetEvaluationTimeInSeconds(5);
    opts.SetMinimumSecondsBetweenFailureNotifications(10);
}).AddInMemoryStorage();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();

app.UseHealthChecks("/health", new HealthCheckOptions
{
    // json response
    ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});

app.UseHealthChecksUI(setup =>
{
    setup.UIPath = "/healthchecks-ui"; // ui path
    setup.ApiPath = "/health-ui-api"; // this is the internal ui api
});

app.Run();
  • Related