Host blazor webassembly app with different base path is not working as described in documentation
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
I have a Blazor Webassembly, .NET hosted application. On the server we host it on, the base path of the app will be mydomain.com/coolapp
. Therefore, to try to get the app to render correctly on the server, I’ve been following Microsofts steps outlined in the “App base path” section of this page: https://docs.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/?view=aspnetcore-6.0&tabs=visual-studio#app-base-path
I’m following all the steps as I see there, but when I try to run the application, I’m getting 404’s from blazor framework files. As far as I can tell, I’m doing everything described in the docs.
Expected Behavior
Following the steps as outlined in documentation should allow me to run my app locally, despite being configured to run at the /coolapp
path when hosted on another server. Instead I get 404’s from key files that are still hosted at the wrong path. Documentation is unclear whether I’m missing something.
Steps To Reproduce
- Create New blazor wasm project, .net core hosted option checked
- Change the base tag in
index.html
to:<base href="/coolapp/" />
- Add this line to
Program.cs
:app.UsePathBase("/coolapp");
- Add
app.UseStaticFiles("/coolapp"); //without this, you get 404's from blazor.framework.js and nothing loads
- Set launch options for command line argument
"commandLineArgs": "--pathbase=/coolapp",
in the"BlazorApp1.Server"
profile - Run BlazorApp1.Server application
- go to
localhost:port/coolapp
path
From there, the app shows “An unhandled error has occurred. Reload” link, indicating that it has loaded some javascript. Inspecting the network tab in dev tools shows that the .dll files are 404ing.
If I navigate to this path directly it 404s, but if I remove the /coolapp
from the url of the dll, it will download the file. So it’s like it’s still being hosted to the base path of /
rather than /coolapp
.
What am I missing? I’m trying the most basic example possible. I pushed my code here for examination: https://github.com/DrLeh/BlazorAppNewBasePath
Exceptions (if any)
No response
.NET Version
6.0.101
Anything else?
Companion SO question: https://stackoverflow.com/questions/71113666/how-to-host-blazor-webassembly-app-with-different-base-path
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (6 by maintainers)
Top GitHub Comments
Thanks @guardrex. Closing this as no further action is pending here.
@guardrex that seems to have helped. I put it near the top, before the
UseBlazorFrameworkFiles()
, etc, and it seems when i run my local/coolapp it’s working properly. However, I tried moving it back down to where it was, rebuilding, clearing browser cache, and it was still working again. So something weird is going on with this functionality. Maybe it’s some other caching mechanism that isn’t clearing when I was making all kinds of changes to try to make it work.