@@ -13,25 +13,51 @@ public void OnPageHandlerSelected(PageHandlerSelectedContext context)
1313
1414 public void OnPageHandlerExecuting ( PageHandlerExecutingContext context )
1515 {
16+ var httpContext = context . HttpContext ;
17+
18+ logger . LogDebug ( "AuthFilter: Page: {Page}, PathBase: {PathBase}, Path: {Path}" ,
19+ context . HandlerInstance ? . GetType ( ) . Name ,
20+ httpContext . Request . PathBase ,
21+ httpContext . Request . Path ) ;
22+
1623 // Skip authentication check for Login page to avoid infinite redirect loop
1724 // Also skip for HealthCheck endpoint used by Kubernetes probes
1825 if ( context . HandlerInstance is Pages . LoginModel or Pages . HealthCheckModel )
1926 {
27+ logger . LogDebug ( "AuthFilter: Skipping auth check for login/health page" ) ;
2028 return ;
2129 }
2230
23- var httpContext = context . HttpContext ;
31+ // Try to get token from session
2432 var token = httpContext . Session . GetString ( "AuthToken" ) ;
2533
34+ // Log session ID and token for debugging
35+ logger . LogDebug ( "AuthFilter: Session ID: {SessionID}, Token present: {HasToken}, CookieCount: {CookieCount}" ,
36+ httpContext . Session . Id ,
37+ ! string . IsNullOrEmpty ( token ) ,
38+ httpContext . Request . Cookies ? . Count ?? 0 ) ;
39+
2640 if ( ! string . IsNullOrEmpty ( token ) )
2741 {
42+ logger . LogDebug ( "AuthFilter: User authenticated with token, allowing access" ) ;
2843 return ;
2944 }
3045
3146 logger . LogInformation ( "Unauthenticated access attempt to {Path}" , httpContext . Request . PathBase + httpContext . Request . Path ) ;
3247
33- // Build the login URL with the correct path base
34- var loginPath = httpContext . Request . PathBase . Add ( "/Login" ) . ToString ( ) ;
48+ // Build the login URL with the correct path base using string concatenation
49+ string loginPath ;
50+ if ( ! string . IsNullOrEmpty ( httpContext . Request . PathBase ) )
51+ {
52+ // Make sure we don't end up with double slashes
53+ loginPath = $ "{ httpContext . Request . PathBase } /Login";
54+ }
55+ else
56+ {
57+ loginPath = "/Login" ;
58+ }
59+
60+ logger . LogDebug ( "AuthFilter: Redirecting to {LoginPath}" , loginPath ) ;
3561 context . Result = new RedirectResult ( loginPath ) ;
3662 }
3763
0 commit comments