Skip to content

Commit f071e3e

Browse files
setting ASPNETCORE_PATHBASE in the admin ui
1 parent 64f3c38 commit f071e3e

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

ECommerce.AdminUI/Filters/AuthenticationFilter.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ namespace ECommerce.AdminUI.Filters;
77
public class AuthenticationFilter : IPageFilter
88
{
99
private readonly ILogger<AuthenticationFilter> _logger;
10-
10+
1111
public AuthenticationFilter(ILogger<AuthenticationFilter> logger)
1212
{
1313
_logger = logger;
1414
}
15-
15+
1616
public void OnPageHandlerSelected(PageHandlerSelectedContext context)
1717
{
1818
// No action needed
@@ -22,19 +22,18 @@ public void OnPageHandlerExecuting(PageHandlerExecutingContext context)
2222
{
2323
// Skip authentication check for Login page to avoid infinite redirect loop
2424
// Also skip for HealthCheck endpoint used by Kubernetes probes
25-
if (context.HandlerInstance is Pages.LoginModel ||
26-
context.HandlerInstance is Pages.HealthCheckModel)
25+
if (context.HandlerInstance is Pages.LoginModel or Pages.HealthCheckModel)
2726
{
2827
return;
2928
}
30-
29+
3130
var httpContext = context.HttpContext;
3231
var token = httpContext.Session.GetString("AuthToken");
33-
32+
3433
if (string.IsNullOrEmpty(token))
3534
{
3635
_logger.LogInformation("Unauthenticated access attempt to {Path}", httpContext.Request.Path);
37-
36+
3837
// Redirect to login page
3938
context.Result = new RedirectToPageResult("/Login");
4039
}

ECommerce.AdminUI/Program.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@
9494
builder.Services.AddScoped<ECommerce.AdminUI.Services.OrderService>();
9595

9696
var app = builder.Build();
97+
var logger = app.Logger;
98+
99+
// Log ASPNETCORE_PATHBASE value at startup
100+
string? pathBase = app.Configuration["ASPNETCORE_PATHBASE"] ?? Environment.GetEnvironmentVariable("ASPNETCORE_PATHBASE");
101+
logger.LogInformation("ASPNETCORE_PATHBASE is set to: \'{PathBase}\'", pathBase);
102+
103+
// Apply the path base if it's set
104+
if (!string.IsNullOrEmpty(pathBase))
105+
{
106+
app.UsePathBase(pathBase);
107+
app.Use((context, next) =>
108+
{
109+
context.Request.PathBase = pathBase;
110+
return next();
111+
});
112+
logger.LogInformation("Path base applied: {PathBase}", pathBase);
113+
}
97114

98115
// Configure the HTTP request pipeline.
99116
if (!app.Environment.IsDevelopment())

0 commit comments

Comments
 (0)