Blazor webassembly subpath doesn't work
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Describe the bug
I want to host a blazor webassembly under a subpath (http://foo.com/bar instead of http://foo.com)
I've tried to set it up using the official documentation https://learn.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/?view=aspnetcore-7.0&tabs=visual-studio#app-base-path
The project is hosted via asp.net core

In the webapplication project, i can set the subpath by using usePathBase, UseStaticFiles and UseBlazorFrameworkFiles
```csharp
var app = builder.Build();
app.UseBlazorFrameworkFiles("/bar");
app.UseStaticFiles("/bar");
app.UsePathBase("/bar");
```
In the wwwroot/index.html, i've set the base to:
```html
```
With those changes, some parts of the webassembly are available under the subpath, but **blazor.webassembly.js** is not. This file is loaded via the subpath, but cannot be provided.

I think what is missing is the StaticWebAssetBasePath (https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/static-files?view=aspnetcore-7.0#static-web-asset-base-path)
I've set this in the webassembly csproj file:
```xml
// I've tried with and without trailing slash
bar
bar/
```
As soon as i add the StaticWebAssetBasePath, blazro webassembly is not retrieved anymore. (Be it using bar/ or bar/index.html)

The complete example is available on github: https://github.com/suntsu42/BlazorSubPathSample
Question: What do i need to configure to host a blazor webassembly project under a subpath?
### Expected Behavior
_No response_
### Steps To Reproduce
_No response_
### Exceptions (if any)
_No response_
### .NET Version
net7.0
### Anything else?
_No response_
Contributor guide
Research direction
Start by reproducing the linked BlazorSubPathSample and review wwwroot/index.html alongside the ASP.NET Core pipeline using UseBlazorFrameworkFiles, UseStaticFiles, and UsePathBase. Check the webassembly project’s StaticWebAssetBasePath setting and the linked hosting documentation. Done means the application and blazor.webassembly.js load correctly when hosted under /bar/.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100