✨新增请求大小限制,默认50M
This commit is contained in:
parent
24c2cd1cc7
commit
2a3d8bab6c
35
Infrastructure/WebExtensions/RequestLimitExtension.cs
Normal file
35
Infrastructure/WebExtensions/RequestLimitExtension.cs
Normal file
@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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"];
|
||||
|
||||
@ -39,12 +39,13 @@
|
||||
"DemoMode": false, //是否演示模式
|
||||
"SingleLogin": false, //是否允许多设备/浏览器登录
|
||||
"workId": 1, //雪花id唯一数字
|
||||
"sqlExecutionTime": 5,//Sql执行时间超过多少秒记录日志并警报
|
||||
"sqlExecutionTime": 5, //Sql执行时间超过多少秒记录日志并警报
|
||||
"Upload": {
|
||||
"uploadUrl": "http://localhost:8888", //本地存储资源访问路径
|
||||
"localSavePath": "", //本地上传默认文件存储目录 wwwroot
|
||||
"maxSize": 15, //上传文件大小限制 15M
|
||||
"notAllowedExt": [ ".bat", ".exe", ".jar", ".js" ]
|
||||
"notAllowedExt": [ ".bat", ".exe", ".jar", ".js" ],
|
||||
"requestLimitSize": 50//请求body大小限制
|
||||
},
|
||||
//阿里云存储配置
|
||||
"ALIYUN_OSS": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user