3

net core web api project

I got one post request method which must be work with a lot of entities

if i use send 20.000 or 30.000 entities its not a problem method works but if i send too large data example 100.000 80.000 not even falling into method and return not found to the client

what should i do ?

here is my method

[HttpPost]
        [DisableRequestSizeLimit]
        public async Task<IActionResult> ArchivePlugs([FromBody] ArchivePlugs model)
        {
            try
            {   
                 await _archivePlugsRepository.AddSynchronizeAsync(model.Archive_Plugs);
                 await _archivePlugProductRepository.AddSynchronizeAsync(model.Archive_PlugProduct);
                 await _archivePlugTaxsRepository.AddSynchronizeAsync(model.Archive_PlugTax);*/

                return OkResult();
            }
            catch
            {
                return BadRequestResult();
            }
        }

what i have tried ?

[DisableRequestSizeLimit]

services.AddMvc().AddJsonOptions(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                options.SerializerSettings.ContractResolver = CustomContractResolver.Instance;
            });

and remomve [frombody] tag and use in this method

 using (var reader = new StreamReader(Request.Body))
                {
                    var body = reader.ReadToEnd();

                    ArchivePlugs results = JsonConvert.DeserializeObject<ArchivePlugs>(body);

                }

but none of them works

1
  • 2
    This might help you. Commented Aug 23, 2019 at 8:27

1 Answer 1

2

If you are using an IIS server you need to set requestLimits in a web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <!-- 4294967295 bytes (4 GiB) is the maximum value-->
        <requestLimits maxAllowedContentLength="52428800" />
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>

You can also set FormOptions in your StartUp class:

public void ConfigureServices(IServiceCollection services)
{
    // Set limits for form options, to accept big data
    services.Configure<FormOptions>(x =>
    {
        x.BufferBody = false;
        x.KeyLengthLimit = 2048; // 2 KiB
        x.ValueLengthLimit = 4194304; // 32 MiB
        x.ValueCountLimit = 2048;// 1024
        x.MultipartHeadersCountLimit = 32; // 16
        x.MultipartHeadersLengthLimit = 32768; // 16384
        x.MultipartBoundaryLengthLimit = 256; // 128
        x.MultipartBodyLengthLimit = 134217728; // 128 MiB
    });

    // Add the mvc framework
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

    ...

} // End of the ConfigureServices method

Another option is send smaller chunks of ArchivePlugs.

Sign up to request clarification or add additional context in comments.

2 Comments

SetCompatibilityVersion not available by the way
Ok, did you set maxAllowedContentLength to 4294967295? SetCompatibilityVersion needs a namespace (Microsoft.AspNetCore.Mvc). You can also increase FormOptions values to maximum values (Int32.MaxValue and Int64.MaxValue).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.