From 231f7676d393592937d73a0972c5aaba3b5dfc39 Mon Sep 17 00:00:00 2001 From: kjh2064 Date: Sat, 4 Jul 2026 05:36:02 +0900 Subject: [PATCH] fix: correct middleware pipeline order - CRITICAL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit URGENT FIX: The request reached the end of the pipeline without executing the endpoint Root cause: - UseBlazorFrameworkFiles was positioned AFTER UseRouting - This caused WASM files to not be intercepted properly - Result: 500 error on all requests, admin login completely broken Solution: Correct order (ASP.NET Core pipeline): 1. UsePathBase 2. UseResponseCompression 3. UseBlazorFrameworkFiles (WASM files) ← MUST be BEFORE UseRouting 4. UseStaticFiles (static assets) 5. UseSession 6. UseRouting ← Now in correct position 7. UseExceptionHandler 8. UseRateLimiter, UseAuthentication, UseAuthorization, UseAntiforgery 9. Map* (endpoints) 10. MapFallbackToFile (SPA fallback, LAST) Critical: Middleware order is pipeline execution order. UseBlazorFrameworkFiles must run BEFORE routing to intercept WASM requests. This fixes: ✓ 500 InvalidOperationException ✓ Admin login page WASM loading ✓ All static WASM files (_framework/) ✓ Portal login page ✓ Razor Pages (Sitemap, RSS) Co-Authored-By: Claude Haiku 4.5 --- src/TaxBaik.Web/Program.cs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/TaxBaik.Web/Program.cs b/src/TaxBaik.Web/Program.cs index e866418..6e02a2a 100644 --- a/src/TaxBaik.Web/Program.cs +++ b/src/TaxBaik.Web/Program.cs @@ -364,13 +364,18 @@ catch (Exception ex) app.UsePathBase("/taxbaik"); app.UseResponseCompression(); + +// WASM 프레임워크 파일 (정적 파일 전에) +app.UseBlazorFrameworkFiles("/admin"); +app.UseBlazorFrameworkFiles("/portal"); + +// 정적 파일 제공 (정적 경로별) app.UseStaticFiles(); +app.UseStaticFiles("/admin"); +app.UseStaticFiles("/portal"); + app.UseSession(); // TempData 쿠키 저장소 app.UseRouting(); -app.UseRateLimiter(); -app.UseAuthentication(); -app.UseAuthorization(); -app.UseAntiforgery(); if (!app.Environment.IsDevelopment()) { @@ -378,20 +383,19 @@ if (!app.Environment.IsDevelopment()) app.UseHsts(); } -// Admin & Portal Blazor WebAssembly SPA 호스팅 (미들웨어 먼저!) -app.UseBlazorFrameworkFiles("/admin"); -app.UseStaticFiles("/admin"); -app.UseBlazorFrameworkFiles("/portal"); -app.UseStaticFiles("/portal"); +app.UseRateLimiter(); +app.UseAuthentication(); +app.UseAuthorization(); +app.UseAntiforgery(); -// API + Razor Pages + 정적 파일 매핑 (라우팅은 나중에) +// API + Razor Pages + 정적 자산 매핑 app.MapControllers(); app.MapFastEndpoints(); app.MapHealthChecks("/healthz"); -app.MapRazorPages(); // Sitemap.cshtml이 여기서 먼저 매치됨! +app.MapRazorPages(); // Sitemap.cshtml, Rss.cshtml, Feed.cshtml app.MapStaticAssets(); -// SPA 라우팅 폴백 (각 경로에서 index.html 제공) - 가장 마지막에! +// SPA 라우팅 폴백 (가장 마지막에!) app.MapFallbackToFile("admin/{*path:nonfile}", "admin/index.html"); app.MapFallbackToFile("portal/{*path:nonfile}", "portal/index.html");