dotnet / dotnet/aspnetcore

404 for static assets in a hosted blazor wasm client with UI Components refactored to razor classlib

Open
#42,924 3 comments 0 reactions 0 assignees View on GitHub
area-mvc feature-static-web-assets investigate
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

When serving the blazor framework files from a different path and moving all the UI code from a blazor wasm project into a razor class lib in preperations for MAUI, the static assets won't be served anymore.

See my [example](https://github.com/msschl/repo_blazor_wasm_razor_classlib_static_assets_bug) repo.

In the server the app serves the blazor framework files form `/core` and serves the fallback file also from `/core`

`Server/Program.cs`
```cs
app.UseBlazorFrameworkFiles("/core");
app.UseStaticFiles();

app.UseRouting();

app.MapRazorPages();
app.MapControllers();
app.MapFallbackToFile("/core/{*path:nonfile}", "core/index.html");

app.Run();
```

In the client all files are moved to the Core razor classlib except for the csprojc, Program.cs and the index.html from the wwwroot folder. In the csprojc the `StaticWebAssetBasePath` tag is added with the value `core`.
The `index.html` is modified to the base `/core/` and the stylesheet links are adapted to `_content/BlazorApp.Core/**`

### Expected Behavior

Referenced razor class libs should still be able to include static web assets.

### Steps To Reproduce

See my [example](https://github.com/msschl/repo_blazor_wasm_razor_classlib_static_assets_bug) repo.

### Exceptions (if any)

_No response_

### .NET Version

dotnet --info .NET SDK (gemäß "global.json"): Version: 6.0.400-preview.22330.6 Commit: da7c9ccceb Laufzeitumgebung: OS Name: Windows OS Version: 10.0.19044 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.400-preview.22330.6\ global.json file: Not found Host: Version: 6.0.7 Architecture: x64 Commit: 0ec02c8c96 .NET SDKs installed: 6.0.302 [C:\Program Files\dotnet\sdk] 6.0.400-preview.22330.6 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Download .NET: https://aka.ms/dotnet-download Learn about .NET Runtimes and SDKs: https://aka.ms/dotnet/runtimes-sdk-info

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.