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.

Host blazor webassembly app with different base path is not working as described in documentation

See original GitHub issue

Is 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

  1. Create New blazor wasm project, .net core hosted option checked
  2. Change the base tag in index.html to: <base href="/coolapp/" />
  3. Add this line to Program.cs: app.UsePathBase("/coolapp");
  4. Add app.UseStaticFiles("/coolapp"); //without this, you get 404's from blazor.framework.js and nothing loads
  5. Set launch options for command line argument "commandLineArgs": "--pathbase=/coolapp", in the "BlazorApp1.Server" profile
  6. Run BlazorApp1.Server application
  7. 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.

enter image description here

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:closed
  • Created 2 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mkArtakMSFTcommented, Mar 30, 2022

Thanks @guardrex. Closing this as no further action is pending here.

1reaction
DrLehcommented, Feb 18, 2022

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to host blazor webassembly app with different base path
I have a Blazor Webassembly, .NET hosted application. On the server we host it on, the base path of the app will be...
Read more >
How to fix Blazor WASM base path problems - elmah.io Blog
This post will show you how to fix a common problem when setting the application base path with Blazor WebAssembly.
Read more >
Host and deploy ASP.NET Core Blazor
The app base path is the app's root URL path. Successful routing in Blazor apps requires framework configuration for any root URL path...
Read more >
How to Build and Secure Web Applications with Blazor
Blazor provides you with two ways to run your Web client application: Blazor Server and Blazor WebAssembly. These are called hosting models.
Read more >
Blazor server deployment
Currently ,To deploy a Standalone Blazor WebAssembly app to Azure app service on Linux is not supported. I have not made any changes...
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