From b5f2c26f718d4b5b014f429e900d1d6d077fe8bc Mon Sep 17 00:00:00 2001 From: clive Date: Sun, 10 Nov 2024 15:00:18 +1100 Subject: [PATCH] Commit: Allow File Types. --- Program.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Program.cs b/Program.cs index 02c138a..b480d28 100644 --- a/Program.cs +++ b/Program.cs @@ -23,7 +23,27 @@ if (!app.Environment.IsDevelopment()) app.UseHttpsRedirection(); app.UseCors(); -app.UseStaticFiles(); +app.UseStaticFiles(new StaticFileOptions +{ + ServeUnknownFileTypes = true, // Allows serving unknown file types + DefaultContentType = "application/octet-stream", // Default content type + OnPrepareResponse = ctx => + { + var path = ctx.File.PhysicalPath.ToLowerInvariant(); + if (path.EndsWith(".woff")) + { + ctx.Context.Response.ContentType = "font/woff"; + } + else if (path.EndsWith(".woff2")) + { + ctx.Context.Response.ContentType = "font/woff2"; + } + else if (path.EndsWith(".ico")) + { + ctx.Context.Response.ContentType = "image/x-icon"; + } + } +}); app.UseRouting();