3

I have a function that saves a list of my entities at once.

public void Save(IEnumerable<SubjectData> subjectDatas)
{
    var request = _requestFactory.CreateRequest("api/subjectData", Method.POST, AccessToken.AccessToken, new List<SubjectData>(subjectDatas));
    var response = Client.Execute(request);
    _responseDeserializer.Deserialize<SubjectData>(response);
}

That's calling a wep API function:

// POST api/<controller>
public void Post([FromBody]List<SubjectData> values)
{
   _subjectDataService.Save(values, User.Identity.Name);
}

when I subjectDatas is a list of about 30, this works fine. However, when subjectDatas is very large (in my test case, over 96000), I get an unexpected error. The response has StatusCode NotFound. what's going on? Why can it suddenly not find the right controller?

esiprogrammer
  • 1,438
  • 1
  • 17
  • 22
Adam R. Grey
  • 1,861
  • 17
  • 30

2 Answers2

0

According to these answers

Is there a limit on how much JSON can hold?

How to increase the json size limit for ASP.NET WebAPI Post call?

Quoting some sources

An ASP.NET request that has lots of form keys, files, or JSON payload members fails with an exception

JavaScriptSerializer.MaxJsonLength Property

There appears to be a default max size of data that can be parse by ASP.Net and in order to increase it you have to make some changes to web.config

This was one of the suggestions offered:

Try adding the aspnet:MaxJsonDeserializerMembers under appSettings in web.config

<add key="aspnet:MaxJsonDeserializerMembers" value="20000"/>

Another Quoted source:

Applications that hit this limit for JSON payloads can modify the ASP.NET appSetting aspnet:MaxJsonDeserializerMembers, as shown below in an ASP.NET application’s configuration file. This setting addresses error message 3 from the "Symptoms" section.

<configuration>
    <appSettings>
        <add key="aspnet:MaxJsonDeserializerMembers" value="1000" />
    </appSettings>
</configuration>

Note Increasing this value above the default setting increases the susceptibility of your server to the Denial of Service vulnerability that is discussed in security bulletin MS11-100.

Community
  • 1
  • 1
Nkosi
  • 235,767
  • 35
  • 427
  • 472
0

According to Max Parameter length in MVC
this is a windows restriction. in your url, the parameter is part of the path. windows restricts a path segments length.

you should change UrlSegmentMaxLength in regedit.

create a DWORD value in the following registery key

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters

UrlSegmentMaxCount

Maximum number of URL path segments. If zero, the count bounded by the maximum value of a ULONG.

Valid value range 0 - 16,383

Http.sys registry settings for Windows

esiprogrammer
  • 1,438
  • 1
  • 17
  • 22