11

My form on the page is a little too large. It collects the monthly measurement data. Please take a look at the sample:

{
"Year":2013,
"Month":3,
"Records":[
    {"Id":0,"Date":"3/1/2013","RiverSection":5,"UserNumber":56},
    {"Id":0,"Date":"3/1/2013","RiverSection":7,"UserNumber":200},
    {"Id":0,"Date":"3/1/2013","RiverSection":8,"UserNumber":556},
    {"Id":0,"Date":"3/2/2013","RiverSection":5,"UserNumber":56},
    {"Id":0,"Date":"3/2/2013","RiverSection":7,"UserNumber":200},
    ...
    ...
    {"Id":0,"Date":"3/31/2013","RiverSection":7,"UserNumber":200}
}

So I am posting the big data to an APIController.

I works fine in my local machine using the Visual Studio debugger server. But after I uploaded the code to the server (IIS 6). It gives a 500 Internal Server Error.

I tried posting some sample data and checked the length of the stringified json.

In one sample data set, the length of my json is 5743, and I got a "success". But if the json size goes up to 17345, I got a 500 Internal Server Error.

So I tried to increase the limit of json. Base on this post

In Web.Config:

<system.web.extensions>
<scripting>
  <webServices>
    <jsonSerialization maxJsonLength="5000000">
    </jsonSerialization>
  </webServices>
</scripting>
</system.web.extensions>

But it is not working.

There is another answer, using:

var serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue;

But where should we place this code? in Global.asax?

Please note I am using an IIS 6. So is it a problem? How can I correctly increase the limit of json size so that my data can hit the WebApi action?

Thank you for any assistance.

Community
  • 1
  • 1
Blaise
  • 21,314
  • 28
  • 108
  • 169
  • This helped me about the same problem: http://stackoverflow.com/a/16436700/1740883 – Pnctovski Oct 03 '13 at 08:14
  • This [link][1] might help in solving the problem. Faced similar issue. [1]: http://stackoverflow.com/questions/12750689/setting-jsonserialization-maxjsonlength-in-asp-net-web-config-gives-500-error/ – Raza Jun 18 '14 at 05:30

1 Answers1

19

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

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

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

Andy T
  • 10,223
  • 5
  • 53
  • 95