Watch Aspire live streamsDocsTry Aspire
Watch Aspire live streamsDocsTry

EndpointHostHelpers Methods

ClassMethods9 members
Provides helper methods for validating localhost addresses and for resolving endpoint URLs against a configured target host.
GetUrlWithTargetHostAsync(EndpointReference, CancellationToken)Section titled GetUrlWithTargetHostAsync(EndpointReference, CancellationToken)staticValueTask<string?>
Gets the URL of the endpoint, adjusting for localhost TLD if configured.
public static class EndpointHostHelpers
{
public static ValueTask<string?> GetUrlWithTargetHostAsync(
EndpointReference endpoint,
CancellationToken cancellationToken = default(CancellationToken))
{
// ...
}
}
endpointEndpointReferenceThe endpoint reference.
cancellationTokenCancellationTokenoptionalA cancellation token.
ValueTask<string?>The URL with the appropriate hostname.
ArgumentNullExceptionThrown when endpoint is null.
When the endpoint's EndpointAnnotation.TargetHost is a localhost TLD (e.g., aspire-dashboard.dev.localhost), the allocated endpoint address will be "localhost" since that's what the service actually binds to. This method returns the URL with the configured TLD hostname instead, which is what users expect to see and use in browsers.
IsDevLocalhostTld(string?)Section titled IsDevLocalhostTld(string?)staticbool
Determines whether the specified host ends with ".dev.localhost".
public static class EndpointHostHelpers
{
public static bool IsDevLocalhostTld(
string? host)
{
// ...
}
}
hoststring?The host to check.
booltrue if the host ends with ".dev.localhost" (case-insensitive); otherwise, false.
IsDevLocalhostTld(Uri?)Section titled IsDevLocalhostTld(Uri?)staticbool
Determines whether the specified URI uses a host that ends with ".dev.localhost".
public static class EndpointHostHelpers
{
public static bool IsDevLocalhostTld(
Uri? uri)
{
// ...
}
}
uriUri?The URI to check.
booltrue if the host ends with ".dev.localhost" (case-insensitive); otherwise, false.
IsLocalhost(string?)Section titled IsLocalhost(string?)staticbool
Determines whether the specified host is "localhost".
public static class EndpointHostHelpers
{
public static bool IsLocalhost(
string? host)
{
// ...
}
}
hoststring?The host to check.
booltrue if the host is "localhost" (case-insensitive); otherwise, false.
IsLocalhost(Uri?)Section titled IsLocalhost(Uri?)staticbool
Determines whether the specified URI uses a host that is "localhost".
public static class EndpointHostHelpers
{
public static bool IsLocalhost(
Uri? uri)
{
// ...
}
}
uriUri?The URI to check.
booltrue if the host is "localhost" (case-insensitive); otherwise, false.
IsLocalhostOrLocalhostTld(string?)Section titled IsLocalhostOrLocalhostTld(string?)staticbool
Determines whether the specified host is "localhost" or uses the ".localhost" top-level domain.
public static class EndpointHostHelpers
{
public static bool IsLocalhostOrLocalhostTld(
string? host)
{
// ...
}
}
hoststring?The host to check.
booltrue if the host is "localhost" (case-insensitive) or ends with ".localhost" (case-insensitive); otherwise, false.
IsLocalhostOrLocalhostTld(Uri?)Section titled IsLocalhostOrLocalhostTld(Uri?)staticbool
Determines whether the specified URI uses a host that is "localhost" or ends with ".localhost".
public static class EndpointHostHelpers
{
public static bool IsLocalhostOrLocalhostTld(
Uri? uri)
{
// ...
}
}
uriUri?
booltrue if the host is "localhost" (case-insensitive) or ends with ".localhost" (case-insensitive); otherwise, false.
IsLocalhostTld(string?)Section titled IsLocalhostTld(string?)staticbool
Determines whether the specified host ends with ".localhost".
public static class EndpointHostHelpers
{
public static bool IsLocalhostTld(
string? host)
{
// ...
}
}
hoststring?The host to check.
booltrue if the host ends with ".localhost" (case-insensitive); otherwise, false.
IsLocalhostTld(Uri?)Section titled IsLocalhostTld(Uri?)staticbool
Determines whether the specified URI uses a host that is "localhost".
public static class EndpointHostHelpers
{
public static bool IsLocalhostTld(
Uri? uri)
{
// ...
}
}
uriUri?The URI to check.
booltrue if the host ends with ".localhost" (case-insensitive); otherwise, false.