From b8222da8e9d3dba775aceadd8d285fae4dc1fc69 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Tue, 24 Sep 2024 20:15:20 +0800 Subject: [PATCH] Serve the files from `AllowedExtraWebContentFolders` of `AbpAspNetCoreContentOptions`. --- .../Builder/AbpApplicationBuilderExtensions.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs index 4dafe38bcc..bd653faf55 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs @@ -145,7 +145,12 @@ public static class AbpApplicationBuilderExtensions } app.UseVirtualStaticFiles(); - app.UseVirtualStaticFiles("Pages"); + + var options = app.ApplicationServices.GetRequiredService>().Value; + foreach (var folder in options.AllowedExtraWebContentFolders) + { + app.UseVirtualStaticFiles(folder); + } return endpoints.MapStaticAssets(staticAssetsManifestPath); } @@ -174,10 +179,18 @@ public static class AbpApplicationBuilderExtensions /// public static IApplicationBuilder UseVirtualStaticFiles(this IApplicationBuilder app, string folder) { + folder = folder.TrimStart('/').TrimEnd('/'); + + var root = Path.Combine(app.ApplicationServices.GetRequiredService().ContentRootPath, folder); + if (!Directory.Exists(root)) + { + return app; + } + app.UseStaticFiles(new StaticFileOptions { ContentTypeProvider = app.ApplicationServices.GetRequiredService(), - FileProvider = new PhysicalFileProvider(Path.Combine(app.ApplicationServices.GetRequiredService().ContentRootPath, folder)), + FileProvider = new PhysicalFileProvider(root), RequestPath = $"/{folder}" });