dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.44k stars 10.02k forks source link

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

Open msschl opened 2 years ago

msschl commented 2 years ago

Is there an existing issue for this?

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

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

Server/Program.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 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

msschl commented 2 years ago

The goal is to create an asp net core server with razor pages. At a specific path (in my case /core) the wasm client application should be served. This client app also includes some razor class libs with static content. This content should be for my understanding also be served from /core. Also, the wasm app is only for authorized users.

@javiercn

Maybe this has also something to do with the MicrosoftAspNetCore.ClientAssets package. It looks like only on publish the assets are copied to the wwwroot folder.

msschl commented 2 years ago

I've also tried without modifing the base to /core See the no_base example on net7.0 latest preview

Eilon commented 2 years ago

Possibly related/similar to https://github.com/dotnet/maui/issues/10898 ?