Class HealthCheckExtensions
- Namespace
- Microsoft.Extensions.Hosting
- Assembly
- Stratara.ServiceDefaults.AspNetCore.dll
Health-check wiring for Stratara ASP.NET Core hosts: registers a default self check + maps the
/health and /alive endpoints.
public static class HealthCheckExtensions
- Inheritance
-
HealthCheckExtensions
- Inherited Members
Methods
AddDefaultHealthChecks<TBuilder>(TBuilder)
Registers a baseline health check (self) that always returns Healthy and is
tagged live, so it shows up on both the /health and /alive endpoints once mapped via
MapDefaultEndpoints(WebApplication, bool).
public static TBuilder AddDefaultHealthChecks<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
Parameters
builderTBuilderThe host application builder.
Returns
- TBuilder
The same builder for chaining.
Type Parameters
TBuilderThe host-builder type.
Examples
Adds the baseline self check, tagged live, which shows up on both endpoints once
they are mapped:
builder.AddDefaultHealthChecks();
MapDefaultEndpoints(WebApplication, bool)
Maps the standard health endpoints: /health (full report) and /alive (only checks tagged
live).
public static WebApplication MapDefaultEndpoints(this WebApplication app, bool requireAuthorizationOnHealth = false)
Parameters
appWebApplicationThe web application to configure.
requireAuthorizationOnHealthboolWhen true, applies
RequireAuthorization()to the/healthendpoint so the full health report (which lists every registered dependency by name and may surface error messages) is only accessible to authenticated callers. The/aliveendpoint stays anonymous because Kubernetes / Aspire liveness probes do not present credentials. Defaults to false to preserve backwards compatibility — see the<remarks>below for guidance.
Returns
- WebApplication
The same app for chaining.
Examples
Maps /health and /alive. Pass true to require authorization on the readiness
endpoint when it is reachable from outside the cluster:
app.MapDefaultEndpoints();
Remarks
Information-disclosure risk on /health: the default mapping returns the full health
report including the names and status of every registered dependency. An unauthenticated attacker
can use it to fingerprint the deployment topology. For internet-exposed hosts, opt in to
requireAuthorizationOnHealth = true, restrict the endpoint to
an internal port via UseUrls / network policy, or replace it with a custom mapping that
returns only an aggregated status.