using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Extensions
{
public static class RequestLimitExtension
{
///
/// 请求body大小设置
///
///
///
public static void AddRequestLimit(this IServiceCollection services, IConfiguration configuration)
{
var sizeM = configuration.GetSection("upload:requestLimitSize").Get();
services.Configure(x =>
{
x.MultipartBodyLengthLimit = sizeM * 1024 * 1024;
x.MemoryBufferThreshold = sizeM * 1024 * 1024;
x.ValueLengthLimit = int.MaxValue;
});
services.Configure(options =>
{
options.Limits.MaxRequestBodySize = sizeM * 1024 * 1024;
});
services.Configure(options =>
{
options.MaxRequestBodySize = sizeM * 1024 * 1024; // 设置最大请求体大小为500MB
});
}
}
}