5

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://learn.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.

  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

From there, running the app seems to work in that it finds the required .js files to get started, but then it fails to load the DLLs to run the app, returning all 404s:

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

Companion dotnet git issue: https://github.com/dotnet/aspnetcore/issues/40205

DLeh
  • 23,806
  • 16
  • 84
  • 128
  • Set the @page directive on the index page to the path you want. – TGnat Feb 14 '22 at 15:04
  • Take a look at this Question - https://stackoverflow.com/questions/71104254/create-a-multiple-webassembly-projects-in-a-single-solution. And check the repo with the code which demos how to run multiple SPAs on the same site, and thus how to run one in a sub-folder. – MrC aka Shaun Curtis Feb 14 '22 at 15:11
  • @MrCakaShaunCurtis I don't want to run multiple in a subfolder, i want it to be at the base. The difference is that the base in local is different than the base when deployed. According to the docs, this is how I would fix that, but it doesn't work. – DLeh Feb 14 '22 at 15:11
  • 1
    NP - I've just downloaded your repo to have a look. – MrC aka Shaun Curtis Feb 14 '22 at 15:15
  • https://stackoverflow.com/questions/63685859/how-and-where-to-set-commandlineargs-pathbase-myapp-in-hosted-blazor-app looks like this is a similar issue – DLeh Feb 14 '22 at 15:16
  • ok i don't know what I did but it seems to be working now. Maybe it was the hot reload that wasn't actually rebuilding my app when i CTRL+F5'd. I'm looking through it now to see if i changed something else since this post – DLeh Feb 14 '22 at 15:41
  • I went back to your original code, full clean and rebuild. And it worked, which is what I originally expected. And to prove that thje basder Url was `coolapp` the API Controller didn't work till I set it to ` [Route("coolapp/[controller]")] ` So yes I agree that the documentation is wrong, but that's often the case! I've removed my answer as its no longer relevant. – MrC aka Shaun Curtis Feb 14 '22 at 17:28
  • @enet. Although at first it would seem so, setting the basepath for Kestrel means that the base URL for the site is `https://localhost:7238/coolapp` so `src="_framework/blazor.webassembly.js"' is from `https://localhost:7238/coolapp`. Which mimics the production environment. – MrC aka Shaun Curtis Feb 14 '22 at 17:34

0 Answers0