Merge pull request '开放全部静态资源的配置' (#176) from koy07555/Admin.NET.Pro:改进静态资源配置 into main

Reviewed-on: http://101.43.53.74:3000/Admin.NET/Admin.NET.Pro/pulls/176
This commit is contained in:
zuohuaijun 2024-11-15 12:21:54 +08:00
commit 0ea36ba9cb
2 changed files with 38 additions and 13 deletions

View File

@ -21,8 +21,9 @@
"DefaultErrorMessage": "系统异常,请联系管理员",
"ThrowBah": true, // Oops.Oh
"LogError": false //
},
},
// (访)
// ".*": "application/octet-stream"访
"StaticContentTypeMappings": {
".dll": "application/octet-stream",
".exe": "application/octet-stream",

View File

@ -20,12 +20,14 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using OnceMi.AspNetCore.OSS;
using SixLabors.ImageSharp.Web.DependencyInjection;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Encodings.Web;
using System.Text.Unicode;
@ -278,20 +280,42 @@ public class Startup : AppStartup
var cpMappings = App.GetConfig<Dictionary<string, string>>("StaticContentTypeMappings");
if (cpMappings != null)
{
foreach (var key in cpMappings.Keys)
if (cpMappings.Keys.Contains(".*"))
{
contentTypeProvider.Mappings[key] = cpMappings[key];
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "wwwroot")),
//RequestPath = "/static",
ServeUnknownFileTypes = true, // 允许服务未知文件类型,以便能处理.dll这种非默认的静态文件类型
//DefaultContentType = "application/octet-stream" // 为未知文件类型设置一个通用的内容类型
DefaultContentType = cpMappings[".*"]
});
}
}
app.UseStaticFiles(new StaticFileOptions
{
ContentTypeProvider = contentTypeProvider
});
//// 启用HTTPS
//app.UseHttpsRedirection();
// 启用OAuth
else
{
foreach (var key in cpMappings.Keys)
{
contentTypeProvider.Mappings[key] = cpMappings[key];
}
app.UseStaticFiles(new StaticFileOptions
{
ContentTypeProvider = contentTypeProvider
});
}
}
else
{
app.UseStaticFiles(new StaticFileOptions
{
ContentTypeProvider = contentTypeProvider
});
}
//// 启用HTTPS
//app.UseHttpsRedirection();
// 启用OAuth
app.UseOAuth();
// 添加状态码拦截中间件