Skip to content

Blazor net9 PathBase not working #59521

Closed as duplicate of#45213
Closed as duplicate of#45213
@peterharding93

Description

@peterharding93

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

There appear to be multiple errors with using net9 Blazor, ServerInteractive rendering and PathBase.

TLDR:

Is there a working example of how I can UsePathBase() in a net 9 blazor application? The documented solutions don't quite work.
My attempts lead me to believe that #48370 is an open issue.

Details:

Using net9, Create a new Blazor WebApp project. Add the line to program.cs:
app.UsePathBase("/app1/");
And in App.razor set the base path:
base href="/app1/"

This fails as described in #57843 - Failed to load resource: the server responded with a status of 405 (Method Not Allowed). That task is marked as closed in RC, but it is still occurring.

I can resolve that by One of two Methods: either explicitly mapping the blazor hub or calling UseRouting. I am not sure which is best:

app.MapBlazorHub("app1/_blazor");
or app.UseRouting();

UseRouting is old know issue from back in net 6 (eg #48370), but I shouldn't have to because that was marked as resolved. This is possibly a regression. The documentation states that I shouldn't need MapBlazorHub either, and this solution doesn't work well if the path base comes from a forwarded header.

These workarounds still leave one open bug - exactly as described in #58046, which is also closed (due to inactivity, not because it was resolved).
BrowerLink is is not retrieved using the path base. I note that blazor.web.js is now using the correct base address (before it was not).

I cannot find a workaround for this, nor find the root cause.

I also note that standalone testing may show this to work - as the BrowserLink file is actually returned correctly without the path base. It is only behind a proxy that requires the path base that the problem appears.

I have a feeling that this is somehow related to the introduction of MapStaticAssets() over UseStaticFiles() - but switching back doesn't seem to resolve the problem.

Expected Behavior

Some documented and robust way to UsePathBase() behind a proxy with Blazor net 9.

Steps To Reproduce

Pretty much as as described in #58046:

  1. Create new Blazor Web App project, globally Server Interactive.
  2. Add app.UsePathBase("/app1/")
  3. Add app.UseRouting();
  4. Set Base path in App.razor
  5. Run the project - it appears to run correctly.
  6. View the page network traffic and notice that something (I think blazor.web.js) is loading to access https://localhost:7116/_vs/browserLink
  7. This Url is incorrect and should be: https://localhost:7116/app1/_vs/browserLink

Exceptions (if any)

No response

.NET Version

9.0.101

Anything else?

VisualStudio.17.Release/17.12.3+35527.113
ASP.NET and Web Tools 17.12.178.10385

In my project file, there are no Nuget packages.
The project has Sdk="Microsoft.NET.Sdk.Web" and TargetFramework of net9.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: DuplicateResolved as a duplicate of another issueNeeds: ReproIndicates that the team needs a repro project to continue the investigation on this issueStatus: Resolvedarea-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions