.net core/IIS/Kestrel 大文件上传大小设置
MultipartBodyLengthLimit 设置每个多部分正文的长度限制。 分析超出此限制的窗体部分时,会引发 InvalidDataException。 默认值为 134,217,728 (128 MB)。 使用 MultipartBodyLengthLimit 中的 Startup.ConfigureServices 设置自定义此限制:
public void ConfigureServices(IServiceCollection services) { services.Configure<FormOptions>(options => { options.MultipartBodyLengthLimit = 1048576L * 5000L;//5G }); } //或 builder.Services.Configure<FormOptions>(options => { options.MultipartBodyLengthLimit = 1048576L * 5000L;//5G });
Kestrel 最大请求正文大小
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.ConfigureKestrel((context, options) => { options.Limits.MaxRequestBodySize = 52428800; }) .UseStartup<Startup>(); }); //或 builder.WebHost.ConfigureKestrel(options => { options.Limits.MaxRequestBodySize = 1048576L * 5000L; //5G }); //或 //在 appsettings.json 中配置终结点 { "Kestrel": {"Limits": { "MaxRequestBodySize ": "100000000" } } }
IIS默认的请求限制 (maxAllowedContentLength) 为 30,000,000 个字节,约为 28.6 MB,最大可设置4294967295 MB(4G)。 在 web.config 文件中自定义此限制:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="4294967295" />
</requestFiltering>
</security>
</system.webServer>
或


浙公网安备 33010602011771号