From f069b70c5b6b1c9a10761dc8fce9d99cb2773a96 Mon Sep 17 00:00:00 2001 From: LD-Reborn Date: Sun, 5 Oct 2025 03:10:47 +0200 Subject: [PATCH] Added endpoint authorization for swagger and elmah --- src/Program.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Program.cs b/src/Program.cs index f3eaa4e..7d76ef1 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -52,6 +52,20 @@ if (!app.Environment.IsDevelopment()) 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(); if (app.Environment.IsDevelopment()) {