diff --git a/src/HealthChecks.UI/Core/ServerAddressesService.cs b/src/HealthChecks.UI/Core/ServerAddressesService.cs index b64d845225..d5bb5d6f7d 100644 --- a/src/HealthChecks.UI/Core/ServerAddressesService.cs +++ b/src/HealthChecks.UI/Core/ServerAddressesService.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Text; namespace HealthChecks.UI.Core @@ -26,6 +27,8 @@ internal string AbsoluteUriFromRelative(string relativeUrl) { var targetAddress = AddressesFeature.Addresses.First(); + Uri.TryCreate(targetAddress, UriKind.Absolute, out var original); + if (targetAddress.EndsWith("/")) { targetAddress = targetAddress[0..^1]; @@ -36,6 +39,13 @@ internal string AbsoluteUriFromRelative(string relativeUrl) relativeUrl = $"/{relativeUrl}"; } + var hostCheck = Uri.CheckHostName(original.DnsSafeHost); + + if (hostCheck != UriHostNameType.Dns) + { + targetAddress = $"{original.Scheme}://{Dns.GetHostName()}:{original.Port}"; + } + return $"{targetAddress}{relativeUrl}"; } }