Description
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:
- Create new Blazor Web App project, globally Server Interactive.
- Add app.UsePathBase("/app1/")
- Add app.UseRouting();
- Set Base path in App.razor
- Run the project - it appears to run correctly.
- View the page network traffic and notice that something (I think blazor.web.js) is loading to access https://localhost:7116/_vs/browserLink
- 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.