Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 793
Blaise Avatar asked Aug 15 '13 20:08

Blaise


1 Answers

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

like image 102
Cloud SME Avatar answered Oct 08 '22 02:10

Cloud SME