From f2f55f81182acfb7f31de70f8d5ed5a7661818a2 Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Wed, 8 Jan 2025 12:38:27 -0700 Subject: [PATCH] Restore favicon, previously was served up automatically by browser but now we want to link it explicitly. also brought back the security features for accessing static files. --- Program.cs | 38 ++++++++++++++++++++++++++++--------- Views/Shared/_Layout.cshtml | 1 + 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Program.cs b/Program.cs index ce9346e..bcb25da 100644 --- a/Program.cs +++ b/Program.cs @@ -106,11 +106,15 @@ var app = builder.Build(); // Configure the HTTP request pipeline. app.UseExceptionHandler("/Home/Error"); +app.UseStaticFiles(); app.UseStaticFiles(new StaticFileOptions { + FileProvider = new PhysicalFileProvider( + Path.Combine(builder.Environment.ContentRootPath, "data", "images")), + RequestPath = "/images", OnPrepareResponse = ctx => { - if (ctx.Context.Request.Path.StartsWithSegments("/images") || ctx.Context.Request.Path.StartsWithSegments("/documents")) + if (ctx.Context.Request.Path.StartsWithSegments("/images")) { ctx.Context.Response.Headers.Add("Cache-Control", "no-store"); if (!ctx.Context.User.Identity.IsAuthenticated) @@ -121,16 +125,21 @@ app.UseStaticFiles(new StaticFileOptions } }); app.UseStaticFiles(new StaticFileOptions -{ - FileProvider = new PhysicalFileProvider( - Path.Combine(builder.Environment.ContentRootPath, "data", "images")), - RequestPath = "/images" -}); -app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider( Path.Combine(builder.Environment.ContentRootPath, "data", "documents")), - RequestPath = "/documents" + RequestPath = "/documents", + OnPrepareResponse = ctx => + { + if (ctx.Context.Request.Path.StartsWithSegments("/documents")) + { + ctx.Context.Response.Headers.Add("Cache-Control", "no-store"); + if (!ctx.Context.User.Identity.IsAuthenticated) + { + ctx.Context.Response.Redirect("/Login"); + } + } + } }); app.UseStaticFiles(new StaticFileOptions { @@ -142,7 +151,18 @@ app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider( Path.Combine(builder.Environment.ContentRootPath, "data", "temp")), - RequestPath = "/temp" + RequestPath = "/temp", + OnPrepareResponse = ctx => + { + if (ctx.Context.Request.Path.StartsWithSegments("/temp")) + { + ctx.Context.Response.Headers.Add("Cache-Control", "no-store"); + if (!ctx.Context.User.Identity.IsAuthenticated) + { + ctx.Context.Response.Redirect("/Login"); + } + } + } }); app.UseRouting(); diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index 43c2773..25cbfec 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -34,6 +34,7 @@ @ViewData["Title"] - LubeLogger +