Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
DrLeh opened this issue Feb 14, 2022 · 7 comments
Closed
1 task done
Labels
area-blazor Includes: Blazor, Razor Components Docs This issue tracks updating documentation Done This issue has been fixed feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly
Milestone

Comments

@DrLeh
Copy link

DrLeh commented Feb 14, 2022

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

@TanayParikh TanayParikh added feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly area-blazor Includes: Blazor, Razor Components labels Feb 14, 2022
@mkArtakMSFT mkArtakMSFT added this to the .NET 7 Planning milestone Feb 14, 2022
@ghost
Copy link

ghost commented Feb 14, 2022

Thanks for contacting us.
We're moving this issue to the .NET 7 Planning milestone for future evaluation / consideration. Because it's not immediately obvious that this is a bug in our framework, we would like to keep this around to collect more feedback, which can later help us determine the impact of it. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@guardrex
Copy link
Contributor

guardrex commented Feb 15, 2022

Hello @DrLeh ... I work on the Blazor docs and have 👀 on your issue/discussion here. We've had our share of successes and failures trying to cover the app base path scenarios with that guidance. Some readers have reported it works perfectly, others ... as in this case ... have trouble with it. We usually sort out the situation and make further updates to the content. I'll take a look at your posted repro as soon as I can, but I'm 🏃 on a few high priority issues at the moment. I hope to be free on Thursday.

UPDATE: Ran one day late. I'll take a look at the repro tomorrow, Friday.

@guardrex
Copy link
Contributor

@DrLeh ... I didn't get too deep into your repro sample before noticing that your call to UsePathBase is rather low in middleware ordering. Can you move it UP in the order? Try placing it immediately after the var app = builder.Build(); line.

This is per our current middleware guidance, but it isn't cross-linked directly to the Blazor App base path section, which I think we'll need to do ... even if it doesn't resolve some or all of the foul routing behavior with your app.

Usually middleware that appears before routing modifies some property of the request, such as UseRewriter, UseHttpMethodOverride, or UsePathBase.

Cross-reference: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-6.0#aspnet-core-endpoint-definition

@DrLeh
Copy link
Author

DrLeh commented 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.

@guardrex
Copy link
Contributor

I see. I can't explain that behavior.

I do think that it makes sense for the Blazor App base path section to recommend the setting early in the request processing pipeline ... first is where I normally place it. I'll open an issue to address that aspect and remain 👂 here for further discussion.

@guardrex
Copy link
Contributor

guardrex commented Feb 18, 2022

@mkArtakMSFT ... I made a doc update to prompt devs to place a call to UseBasePath early in the request processing pipeline to set the base path prior to middlewares that interact with the path. If that's all that this requires at this time, the PU issue can close. Otherwise, I'm 👂 here for additional relevant doc guidance for the App base path section (the update that I made is live now).

@mkArtakMSFT
Copy link
Member

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

@mkArtakMSFT mkArtakMSFT added Done This issue has been fixed Docs This issue tracks updating documentation and removed investigate labels Mar 30, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Apr 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components Docs This issue tracks updating documentation Done This issue has been fixed feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly
Projects
None yet
Development

No branches or pull requests

4 participants