Skip to content

Fix dashboard URL logging#14287

Merged
davidfowl merged 3 commits intomainfrom
jamesnk/dashboardurl-fix
Feb 2, 2026
Merged

Fix dashboard URL logging#14287
davidfowl merged 3 commits intomainfrom
jamesnk/dashboardurl-fix

Conversation

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Feb 2, 2026

Description

Fixes #14248

The value returned from EndpointReference is the correct port, but has a localhost host. It doesn't reflect the target host value.

Update places where GetValueAsync is used to resolve dashboard URLs with a helper method that corrects the host.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@JamesNK JamesNK requested a review from davidfowl February 2, 2026 09:48
@JamesNK JamesNK requested a review from mitchdenny as a code owner February 2, 2026 09:48
@JamesNK JamesNK added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Feb 2, 2026
Copilot AI review requested due to automatic review settings February 2, 2026 09:48
@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14287

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 14287"

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a regression where dashboard URLs displayed "localhost" instead of the configured localhost TLD (e.g., "aspire-dashboard.dev.localhost") when using the --localhost-tld template option. The issue affected the Aspire 13.2 project template.

Changes:

  • Introduced EndpointHostHelpers.GetUrlWithTargetHostAsync() helper method to resolve endpoint URLs with the configured TLD hostname when applicable
  • Updated dashboard URL logging in DashboardEventHandlers.cs to use the new helper method
  • Updated API base URL resolution in DashboardUrlsHelper.cs to use the new helper method
  • Expanded test coverage to verify correct URL resolution for multiple scenarios including localhost TLDs

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/Aspire.Hosting/ApplicationModel/EndpointHostHelpers.cs Added internal helper method GetUrlWithTargetHostAsync() to adjust endpoint URLs for localhost TLD configuration
src/Aspire.Hosting/Dashboard/DashboardEventHandlers.cs Updated dashboard URL logging to use the new helper method instead of direct GetValueAsync()
src/Aspire.Hosting/Backchannel/DashboardUrlsHelper.cs Updated API base URL resolution to use the new helper method
tests/Aspire.Hosting.Tests/Dashboard/DashboardLifecycleHookTests.cs Converted test to theory with multiple test cases covering localhost, localhost TLDs, and different schemes

Comment on lines +138 to +139
var uri = new Uri(allocatedUrl);
return $"{uri.Scheme}://{targetHost}:{uri.Port}";
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Uri constructor on line 138 could throw an exception if allocatedUrl is not a valid absolute URI. While the check on line 127 ensures it's not null or empty, it doesn't validate that it's a well-formed URI. Consider adding a try-catch block or using Uri.TryCreate to handle potential format exceptions gracefully, especially since this is an internal utility method that may be called from various contexts.

Suggested change
var uri = new Uri(allocatedUrl);
return $"{uri.Scheme}://{targetHost}:{uri.Port}";
if (Uri.TryCreate(allocatedUrl, UriKind.Absolute, out var uri))
{
return $"{uri.Scheme}://{targetHost}:{uri.Port}";
}
// If the allocated URL is not a valid absolute URI, return it unchanged.
return allocatedUrl;

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

🎬 CLI E2E Test Recordings

The following terminal recordings are available for commit a23539e:

Test Recording
CreateAndDeployToDockerCompose ▶️ View Recording
CreateAndDeployToDockerComposeInteractive ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateEmptyAppHostProject ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording

📹 Recordings uploaded automatically from CI run #21586229647

@davidfowl davidfowl merged commit ed5eb4e into main Feb 2, 2026
335 checks passed
@davidfowl davidfowl deleted the jamesnk/dashboardurl-fix branch February 2, 2026 17:45
@dotnet-policy-service dotnet-policy-service bot added this to the 13.2 milestone Feb 2, 2026
@karolz-ms
Copy link
Contributor

There is probably a room for improvement for DCP here as well--opened microsoft/dcp#68 to pursue that.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AspireE2E] .dev.localhost URL not reflected by --localhost-tld template in Aspire 13.2 Project Template

4 participants