:sparkles:新增请求大小限制,默认50M

This commit is contained in:
不做码农
2023-12-23 20:26:56 +08:00
parent 24c2cd1cc7
commit 2a3d8bab6c
3 changed files with 40 additions and 2 deletions
@@ -0,0 +1,35 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace ZR.Infrastructure.WebExtensions
{
public static class RequestLimitExtension
{
/// <summary>
/// 请求body大小设置
/// </summary>
/// <param name="services"></param>
/// <param name="configuration"></param>
public static void AddRequestLimit(this IServiceCollection services, IConfiguration configuration)
{
var sizeM = configuration.GetSection("upload:requestLimitSize").Get<int>();
services.Configure<FormOptions>(x =>
{
x.MultipartBodyLengthLimit = sizeM * 1024 * 1024;
x.MemoryBufferThreshold = sizeM * 1024 * 1024;
x.ValueLengthLimit = int.MaxValue;
});
services.Configure<KestrelServerOptions>(options =>
{
options.Limits.MaxRequestBodySize = sizeM * 1024 * 1024;
});
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = sizeM * 1024 * 1024; // 设置最大请求体大小为500MB
});
}
}
}
+2
View File
@@ -47,6 +47,8 @@ builder.Services.AddSingleton(new AppSettings(builder.Configuration));
builder.Services.AddAppService();
//开启计划任务
builder.Services.AddTaskSchedulers();
//请求大小限制
builder.Services.AddRequestLimit(builder.Configuration);
//注册REDIS 服务
var openRedis = builder.Configuration["RedisServer:open"];
+2 -1
View File
@@ -44,7 +44,8 @@
"uploadUrl": "http://localhost:8888", //本地存储资源访问路径
"localSavePath": "", //本地上传默认文件存储目录 wwwroot
"maxSize": 15, //上传文件大小限制 15M
"notAllowedExt": [ ".bat", ".exe", ".jar", ".js" ]
"notAllowedExt": [ ".bat", ".exe", ".jar", ".js" ],
"requestLimitSize": 50//请求body大小限制
},
//阿里云存储配置
"ALIYUN_OSS": {