Merge pull request #68 from LD-Reborn/66-bugfix-swagger-and-other-endpoints-visible-outside-of-development-environment

Added endpoint authorization for swagger and elmah
This commit is contained in:
LD50
2025-10-05 03:11:32 +02:00
committed by GitHub

View File

@@ -52,6 +52,20 @@ if (!app.Environment.IsDevelopment())
app.UseExceptionHandler("/Home/Error"); app.UseExceptionHandler("/Home/Error");
} }
app.Use(async (HttpContext context, RequestDelegate next) =>
{
if (context.Request.Path.StartsWithSegments("/elmah") || context.Request.Path.StartsWithSegments("/swagger"))
{
if (!(context.User?.Identity?.IsAuthenticated ?? false))
{
context.Response.Redirect("/Home/Login");
return;
}
}
await next(context);
});
app.UseElmah(); app.UseElmah();
if (app.Environment.IsDevelopment()) if (app.Environment.IsDevelopment())
{ {