dotnet
runtime_error
ai_generated
true
Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException:请求正文过大。最大请求正文大小为 30000000 字节。
Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Request body too large. The max request body size is 30000000 bytes.
ID: dotnet/kestrel-request-body-too-large
90%修复率
89%置信度
1证据数
2023-02-14首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| ASP.NET Core 6.0 | active | — | — | — |
| ASP.NET Core 7.0 | active | — | — | — |
| ASP.NET Core 8.0 | active | — | — | — |
根因分析
传入的 HTTP 请求正文超过了 Kestrel 服务器配置的最大请求正文大小限制,默认约为 28.6 MB(30,000,000 字节),或可通过 MaxRequestBodySize 自定义。
English
The incoming HTTP request body exceeds the Kestrel server's configured maximum request body size limit, which defaults to ~28.6 MB (30,000,000 bytes) or can be customized via MaxRequestBodySize.
官方文档
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/options解决方案
-
使用 [RequestSizeLimit] 属性增加特定端点的限制:[RequestSizeLimit(50_000_000)] public IActionResult Upload() { ... } -
在 Program.cs 中全局配置 Kestrel:builder.WebHost.ConfigureKestrel(options => options.Limits.MaxRequestBodySize = 50 * 1024 * 1024); // 50 MB
无效尝试
常见但无效的做法:
-
80% 失败
This disables the limit entirely, risking denial-of-service from large payloads.
-
70% 失败
Kestrel checks the uncompressed size; compression does not bypass the limit.