Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iis Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException:请求正文太大_Iis_Asp.net Core_Asp.net Core Mvc - Fatal编程技术网

Iis Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException:请求正文太大

Iis Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException:请求正文太大,iis,asp.net-core,asp.net-core-mvc,Iis,Asp.net Core,Asp.net Core Mvc,我正在尝试将100MB的电影上载到我的ASP.NET核心应用程序 我已在我的操作上设置此属性: [RequestSizeLimit(1_000_000_000)] 我还更改了我的Web.config文件,包括: 换句话说,我已经告诉IIS允许高达700MBs的文件,我还告诉ASP.NET Core允许近1GB的文件 但我还是犯了那个错误。我找不到答案。有什么想法吗 附言:使用这些配置,我可以通过30MB的默认大小。我可以上传50或70兆字节的文件。我想你只需要:[DisableReques

我正在尝试将100MB的电影上载到我的ASP.NET核心应用程序

我已在我的操作上设置此属性:

[RequestSizeLimit(1_000_000_000)]
我还更改了我的
Web.config
文件,包括:


换句话说,我已经告诉IIS允许高达700MBs的文件,我还告诉ASP.NET Core允许近1GB的文件

但我还是犯了那个错误。我找不到答案。有什么想法吗


附言:使用这些配置,我可以通过30MB的默认大小。我可以上传50或70兆字节的文件。

我想你只需要:[DisableRequestSizeLimit]

下面是一个解决方案,它可以帮助我将包含其他表单数据的Zip文件上传到运行.NETCore3的API中

//包含表单数据的zip文件需要MultipartBodyLengthLimit。
//[DisableRequestSizeLimit]适用于KESTREL服务器,但不适用于IIS服务器
//对于IIS:webconfig。。。
[RequestFormLimits(ValueLengthLimit=int.MaxValue,MultipartBodyLengthLimit=int.MaxValue)]
[DisableRequestSizeLimit]
[使用(“多部分/表单数据”)]//用于包含表单数据的Zip文件
[HttpPost(“MyCustomRoute”)]
public IActionResult UploadedZippedFiles([FromForm]MyCustomFormObject formData)
{ }
注意:这是我从迁移应用程序时遇到的问题 asp.net核心2.1到3.0

为了在asp.net core 3.0中修复此问题,我已将program.cs更改为修改最大请求正文大小,如下所示

.ConfigureWebHostDefaults(webBuilder =>
{
    webBuilder
    .ConfigureKestrel(serverOptions =>
    {
        serverOptions.Limits.MaxRequestBodySize = 157286400;
    })
    .UseStartup<Startup>();
})
公共类程序
{
公共静态void Main(字符串[]args)
{
CreateWebHostBuilder(args.Build().Run();
}
公共静态IWebHostBuilder CreateWebHostBuilder(字符串[]args)
{
返回WebHost.CreateDefaultBuilder(args)
.ConfigureKestrel((上下文、选项)=>
{
options.Limits.MaxRequestBodySize=737280000;
})
.UseStartup();
}
}
}
我的意思是我刚刚添加了
ConfigureKestrel
部分,并在我的操作方法
[RequestSizeLimit(737280000)]
上面添加了一个属性,如下所示

[HttpPost]
[RequestSizeLimit(737280000)]
[路线(“某些路线”)]
公共异步任务MyActionMethodAsync([FromForm]MyViewModel MyViewModel)
{
//一些代码
返回视图();
}
我的应用程序再次开始正常运行,没有抛出
BadHttpRequestException:RequestBody过大

参考资料:

对于我(Asp.net core 3.1),解决方案是在
ConfigureServices
方法的
Startup.cs
中添加这些行:

//200 MB
const int maxRequestLimit=209715200;
//如果使用IIS
配置(选项=>
{
options.MaxRequestBodySize=maxRequestLimit;
});
//如果使用红隼
配置(选项=>
{
options.Limits.MaxRequestBodySize=maxRequestLimit;
});
services.Configure(x=>
{
x、 ValueLengthLimit=maxRequestLimit;
x、 MultipartBodyLengthLimit=maxRequestLimit;
x、 MultipartHeadersLengthLimit=maxRequestLimit;
});
和编辑
web.config


我正在使用web.config来配置它。(而我们的api托管在IIS中)


但现在我们正在将api迁移到linux容器并使用Kestral。然后我像下面这样配置

.ConfigureWebHostDefaults(webBuilder =>
{
    webBuilder
    .ConfigureKestrel(serverOptions =>
    {
        serverOptions.Limits.MaxRequestBodySize = 157286400;
    })
    .UseStartup<Startup>();
})
.ConfigureWebHostDefaults(webBuilder=>
{
韦伯造船厂
.ConfigureKestrel(服务器选项=>
{
serverOptions.Limits.MaxRequestBodySize=157286400;
})
.UseStartup();
})

157286400=150mb

看,我差点就放弃了,但你的解决方案很有魅力!我还发现这个链接在全新的.Net Core 3.1 MVC应用程序上对我很有用。其他解决方案,比如在
Startup.cs
上更新
ConfigureServices
和@YorJaggy的url(我在本网站之前找到过)都不起作用。