Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException:请求正文太大 [英] Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Request body too large
问题描述
我正在尝试将100MB的影片上传到我的ASP.NET Core应用程序.
I'm trying to upload a 100MB film to my ASP.NET Core application.
我已在操作中设置此属性:
I've set this attribute on my action:
[RequestSizeLimit(1_000_000_000)]
我还更改了Web.config
文件,使其包含:
And I also changed my Web.config
file to include:
<security>
<requestFiltering>
<!-- This will handle requests up to 700MB (CD700) -->
<requestLimits maxAllowedContentLength="737280000" />
</requestFiltering>
</security>
换句话说,我已经告诉IIS允许最大700MB的文件,并且我还告诉ASP.NET Core允许接近1GB的文件.
In other words, I've told IIS to allow files up to 700MBs and I've also told ASP.NET Core to allow files of near 1GB.
但我仍然会收到该错误.而且我找不到答案.有什么想法吗?
But I still get that error. And I can't find the answer. Any ideas?
P.S:使用这些配置,我可以传递30MB的默认大小.我可以上传50或70兆字节的文件.
P.S: Using these configurations, I could pass the 30MB default size. I can upload files of 50 or 70 Mega Bytes.
推荐答案
我认为您只需要:[DisableRequestSizeLimit]
I think you just need: [DisableRequestSizeLimit]
下面是一个对我有用的解决方案,用于将Zip文件和其他表单数据上传到运行.Net Core 3的API
below is a solution that worked for me to upload Zip files with additional form data to an API running .Net Core 3
// MultipartBodyLengthLimit was needed for zip files with form data.
// [DisableRequestSizeLimit] works for the KESTREL server, but not IIS server
// for IIS: webconfig... <requestLimits maxAllowedContentLength="102428800" />
[RequestFormLimits(ValueLengthLimit = int.MaxValue, MultipartBodyLengthLimit = int.MaxValue)]
[DisableRequestSizeLimit]
[Consumes("multipart/form-data")] // for Zip files with form data
[HttpPost("MyCustomRoute")]
public IActionResult UploadZippedFiles([FromForm] MyCustomFormObject formData)
{ }
这篇关于Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException:请求正文太大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!