From 6e369aabef448e8a269c60986c507783e321b78c Mon Sep 17 00:00:00 2001 From: Pierre Arnaud Date: Fri, 30 Jan 2026 16:58:29 +0100 Subject: [PATCH] Fix static files and CSS asset reference for SignalR sample - Fix middleware order: UseAntiforgery must be between UseRouting and UseEndpoints - Add UseStaticFiles() to serve wwwroot content - Fix scoped CSS bundle reference: use lowercase 'electronnet-samples-blazorsignalr.styles.css' to match generated asset name - Add HTTP request logging for debugging - Enable detailed logging for routing and static files in development --- .../Components/App.razor | 2 +- src/ElectronNET.Samples.BlazorSignalR/Program.cs | 16 ++++++++++++++-- .../appsettings.Development.json | 4 +++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/ElectronNET.Samples.BlazorSignalR/Components/App.razor b/src/ElectronNET.Samples.BlazorSignalR/Components/App.razor index 0c80651..c5a59ba 100644 --- a/src/ElectronNET.Samples.BlazorSignalR/Components/App.razor +++ b/src/ElectronNET.Samples.BlazorSignalR/Components/App.razor @@ -8,7 +8,7 @@ - + diff --git a/src/ElectronNET.Samples.BlazorSignalR/Program.cs b/src/ElectronNET.Samples.BlazorSignalR/Program.cs index 84265a5..fb61135 100644 --- a/src/ElectronNET.Samples.BlazorSignalR/Program.cs +++ b/src/ElectronNET.Samples.BlazorSignalR/Program.cs @@ -52,6 +52,14 @@ builder.WebHost.UseElectron(args, async () => var app = builder.Build(); +// Log all HTTP requests for debugging +app.Use(async (context, next) => +{ + Console.WriteLine($"[HTTP] {context.Request.Method} {context.Request.Path}{context.Request.QueryString}"); + await next(); + Console.WriteLine($"[HTTP] {context.Request.Method} {context.Request.Path} -> {context.Response.StatusCode}"); +}); + // Enable WebSockets (required for SignalR) app.UseWebSockets(); @@ -70,16 +78,20 @@ if (!app.Environment.IsDevelopment()) app.UseHttpsRedirection(); } +// Serve static files (CSS, JS, images, etc.) +app.UseStaticFiles(); + app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true); +// UseAntiforgery must be between UseRouting and UseEndpoints +app.UseAntiforgery(); + // Use endpoints for SignalR hub app.UseEndpoints(endpoints => { endpoints.MapHub("/electron-hub"); }); -app.UseAntiforgery(); - app.MapStaticAssets(); app.MapRazorComponents() .AddInteractiveServerRenderMode(); diff --git a/src/ElectronNET.Samples.BlazorSignalR/appsettings.Development.json b/src/ElectronNET.Samples.BlazorSignalR/appsettings.Development.json index 8153d14..ca97cdc 100644 --- a/src/ElectronNET.Samples.BlazorSignalR/appsettings.Development.json +++ b/src/ElectronNET.Samples.BlazorSignalR/appsettings.Development.json @@ -2,7 +2,9 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning", + "Microsoft.AspNetCore": "Debug", + "Microsoft.AspNetCore.Routing": "Debug", + "Microsoft.AspNetCore.StaticFiles": "Debug", "Microsoft.AspNetCore.SignalR": "Debug", "Microsoft.AspNetCore.Http.Connections": "Debug" }