Blazor: Navigation.BaseUri Incorrect on Forwarded Ports
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
Environment: GitHub Codespaces launchSettings URL: http://localhost:5000
NavigationManager.BaseUri does not properly resolve when running in an environment with port forwarding (to either the initial port or the forwarded port). It will initially be set to http://localhost/ before flashing to the forwarded port. This prevents the use of NavigationManager.BaseUri for composing API calls in OnInitializedAsync.
Initial Component Render

Moments After Render

Expected Behavior
NavigationManager.BaseUri should immediately reflect the forwarded port URL so that API calls can be reliably constructed.
Steps To Reproduce
Run the following repo in a GitHub Codespace:
https://github.com/JaimeStill/BlazorPortForwardedBaseUriIssue
See Index.razor.
Exceptions (if any)
No response
.NET Version
6.0.402
Anything else?
.NET SDK (reflecting any global.json): Version: 6.0.402 Commit: 6862418796
Runtime Environment: OS Name: ubuntu OS Version: 20.04 OS Platform: Linux RID: ubuntu.20.04-x64 Base Path: /usr/local/dotnet/6/sdk/6.0.402/
global.json file: Not found
Host: Version: 6.0.10 Architecture: x64 Commit: 5a400c212a
.NET SDKs installed: 6.0.402 [/usr/local/dotnet/6/sdk]
.NET runtimes installed: Microsoft.AspNetCore.App 6.0.10 [/usr/local/dotnet/6/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.10 [/usr/local/dotnet/6/shared/Microsoft.NETCore.App]
Issue Analytics
- State:
- Created 10 months ago
- Comments:17 (12 by maintainers)

Top Related StackOverflow Question
@JaimeStill thanks for contacting us.
That is because
https://jaimestill-literate-space-waffle-v6qgjjj56rvcw596-5000.preview.app.github.devis only accessible “from outside”. (meaning your browser).Codespaces apparently has not setup
jaimestill-literate-space-waffle-v6qgjjj56rvcw596-5000.preview.app.github.devto redirect to localhost, which is what should happen.This seems to be something specific to how codespaces sets up the environment and port forwarding. NavigationManager is initialized with HttpContext.Request values during prerendering and it is initialized with the value from the document.baseUri and location.href when it becomes interactive, so that will explain the flashing.
The fact that it does not happen when the app is not prerendered is also strong evidence of that, tied to the fact that you can only reach yourself from within the app via localhost.
Thank you for contacting us. Due to a lack of activity on this discussion issue we’re closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn’t been addressed yet, please file a new issue.
This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue!