aspnet / Diagnostics

[Archived] Diagnostics middleware for reporting info and handling exceptions and errors in ASP.NET Core, and diagnosing Entity Framework Core migrations errors. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
213 stars 108 forks source link

Allow UseHealthChecks to accept root path #468

Closed andysleigh closed 6 years ago

andysleigh commented 6 years ago

Currently if I try to set up a health check on the root path by calling UseHealthCheck("") then it throws an ArgumentException with the message "A URL path must be provided". Directly mapping the HealthCheckMiddleware to the root path using the code below works fine:

app.Map("", b => b.UseMiddleware<HealthCheckMiddleware>());

I can't see any good reason to enforce this in UseHealthCheck so can we remove the path check from HealthCheckApplicationBuilderExtensions.cs please? At my work we write a lot of web APIs with ASP.NET Core and tend to put a a health check on the root (currently with our own HealthCheckMiddleware class).

rynowak commented 6 years ago

Yep, this is something we should fix. Thanks.

rynowak commented 6 years ago

@andysleigh - are you trying to bind to the root url or to all URLs?.

For instance Map("", ...) will handle all URLs. Map handles all URLs that are suffixes of what you put in.

andysleigh commented 6 years ago

@rynowak - Yes I was trying to use bind to the root URL. I can now see I'll need to use MapWhen to do this. Thanks.

app.MapWhen(c => c.Request.Path == "/", b => b.UseMiddleware<HealthCheckMiddleware>());