question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor: Navigation.BaseUri Incorrect on Forwarded Ports

See original GitHub issue

Is 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 image

Moments After Render image

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:closed
  • Created 10 months ago
  • Comments:17 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
javiercncommented, Nov 16, 2022

@JaimeStill thanks for contacting us.

That is because https://jaimestill-literate-space-waffle-v6qgjjj56rvcw596-5000.preview.app.github.dev is only accessible “from outside”. (meaning your browser).

Codespaces apparently has not setup jaimestill-literate-space-waffle-v6qgjjj56rvcw596-5000.preview.app.github.dev to 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.

0reactions
msftbot[bot]commented, Jan 16, 2023

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core Blazor routing and navigation
This article explains how to manage Blazor app request routing and how to use the NavLink component to create navigation links.
Read more >
Why is Blazor WASM routing not using correct base URI ...
A Blazor WASM project I'm developing routes as expected when debugging on localhost. For example, after logging in, if successful, NavigateTo("/ ...
Read more >
How to Secure Blazor WASM Applications with Auth0
Blazor allows you to build your WebAssembly (also known as WASM) ... So, open the _Imports.razor file in the Client folder and add...
Read more >
Hosting both Blazor Server and WebAssembly in single ...
Start the application and open it in browser. Open browser Developer tools and open Network tab. There should be blazor.webassembly.js in list ...
Read more >
Blazor behind reverse proxy. 168. NET Core host application is
IIS will act as a reverse proxy to forward requests from “localhost” OR “reverseproxy. The problem. Routing requests for page components in a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found