-
Notifications
You must be signed in to change notification settings - Fork 817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relative paths for the health-check UI only appear to be working on local iis express or Kestrel #1420
Labels
Comments
Had this issue as well. Here is my workaround: Add package public static class IisHelper
{
public static string? GetIisUrl(IWebHostEnvironment env)
{
try
{
using ServerManager serverManager = new ServerManager();
var site = serverManager.Sites.FirstOrDefault(s => s.Name == env.ApplicationName);
if (site?.Bindings?.Count > 0)
{
var binding = site.Bindings.First();
var host = binding.Host;
if (string.IsNullOrWhiteSpace(host))
{
if (binding.EndPoint.Address != IPAddress.Any)
{
host = binding.EndPoint.Address.ToString();
}
else
{
host = Environment.MachineName;
}
}
var url = $"{binding.Protocol}://{host}:{binding.EndPoint.Port}";
Log.Information("IIS serving url: {Url}", url);
return url;
}
}
catch(Exception ex)
{
Log.Warning(ex, "Unable to load IIS Url");
}
return null;
}
} Call it like this: // Health Checks
string? iisUrl = IisHelper.GetIisUrl(builder.Environment);
builder.Services
.AddHealthChecksUI(setup => setup.AddHealthCheckEndpoint("SWSIdentity", (iisUrl ?? string.Empty) + "/healthz"))
.AddInMemoryStorage()
.Services
.AddHealthChecks()
// ... |
I think this issue might be related aspnet/Hosting#956 |
After being inspired by @Khaos66 this worked for me..
//Program.cs
//Apsettings.json
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Relative paths for the health-check UI only appear to be working on local iis express or Kestrel when run from Visual Studio. I am not able to get this to work correctly in a deployed environment. When deployed, the UI comes up, but displays an error message stating: Could not get endpoint uri from configuration. I am using .net6. My appsettings.json config section looks like this:
"HealthChecksUI": {
"HealthChecks": [
{
"Name": "Configuration-Service",
"Uri": "/healthz"
}
],
"Webhooks": [
{
"Name": "",
"Uri": "",
"Payload": "",
"RestoredPayload": ""
}
]
},
My program.cs file looks like this:
...
builder.Services.AddHealthChecks()
...
builder.Services.AddHealthChecksUI().AddInMemoryStorage();
...
app.MapHealthChecks("/healthz", new HealthCheckOptions
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
...
app.UseHttpsRedirection();
app.MapHealthChecksUI();
app.UseRouting();
app.MapControllers();
app.Run();
The text was updated successfully, but these errors were encountered: