简体   繁体   English

.net 核心请求太大

[英].net core request too large

I have a .net core 3.1 application I'm running on localhost.我有一个在本地主机上运行的.net core 3.1应用程序。 I'm sending over a List of 50k objects with 50 properties.我正在发送一个包含 50 个属性的 50k 个对象的列表。

The response I'm getting is REQUEST IS TOO LARGE from the server I POST to.我得到的响应是我发布到的服务器的REQUEST IS TOO LARGE

I've tried editing startup.cs with the following我尝试使用以下内容编辑 startup.cs

        services.Configure<IISServerOptions>(options =>

        {

            options.MaxRequestBodySize = int.MaxValue;

        });



        services.Configure<KestrelServerOptions>(options =>

        {

            options.Limits.MaxRequestBodySize = long.MaxValue;

        });



        services.Configure<FormOptions>(x =>

        {

            x.ValueLengthLimit = int.MaxValue;

            x.MultipartBodyLengthLimit = long.MaxValue;

            x.MultipartHeadersLengthLimit = int.MaxValue;

        });

How ever all three have failed.怎么这三个都失败了。 How can I increae the request body limit?如何增加请求正文限制?

I personally think that instead of changing the default post request maximum size you should send your objects in batches by 10k or by 5k, so each request fits the default maximum size.我个人认为,与其更改默认的发布请求最大大小,不如按 10k 或 5k 分批发送对象,因此每个请求都符合默认的最大大小。 Changing IIS default values for requests can lead to nasty DOS exploits.更改请求的 IIS 默认值可能会导致讨厌的 DOS 攻击。 However, if you want to change IIS's maximum request size anyway here is a tutorial on how to do this https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/requestfiltering/requestlimits/ ie you have to this in both the IIS settings of your operating systems and Startup.cs of your ASP.NET core application otherwise request will still be limit to 30000000 bytes no matter the settings in your Startup.cs但是,如果您想更改 IIS 的最大请求大小,这里有一个关于如何执行此操作的教程https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/requestfiltering/requestlimits/即您必须在操作系统的 IIS 设置和 ASP.NET 核心应用程序的 Startup.cs 中都这样做,否则无论 Startup.cs 中的设置如何,请求仍将限制为 30000000 字节

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM