0

I use asp.net mvc 2.0 and jquery for my web application. when I tried to call a MVC action by Jquery Ajax with a JSON object about 30K, my server action did not get called. I searched for a solution and changed the maxJsonLength property in web.config. but that didn't work.

I'll appreciate any help.

Hosein
  • 581
  • 1
  • 7
  • 29
  • This is your answer : http://stackoverflow.com/questions/1151987/can-i-set-an-unlimited-length-for-maxjsonlength-in-web-config#answer-1151993 – hemma731 May 23 '13 at 10:48
  • Does this post help? http://stackoverflow.com/questions/10966328/the-json-request-was-too-large-to-be-deserialized – Tim B James May 23 '13 at 10:49
  • @hemma731: No it isn't; I did that and nothing changed. – Hosein May 23 '13 at 11:21
  • @TimBJames: I tried the second part of that answer: aspnet:MaxJsonDeserializerMembers, but that dose not help either. – Hosein May 23 '13 at 11:23

1 Answers1

3

I solved my problem and in case any body has this problem in future, here is the solution.

My actual problem was not the length of the JSON object. It was the numbers of keys in that object. Actually there is a limit for the keys number you can send via the ajax post request in ASP.NET and in case you need more, youe should increase it in web.config appSettings section:

<add key="aspnet:MaxHttpCollectionKeys" value="100000" />

And also don't forget to add these two configs in similar cases to some big numbers:

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

and

<system.web.extensions>
  <scripting>
    <webServices>
      <jsonSerialization maxJsonLength="200000000"/>
    </webServices>
  </scripting>
</system.web.extensions>
Hosein
  • 581
  • 1
  • 7
  • 29
  • 1
    Note: Setting this too high can put a heavy load on your servers and potentially DOS them. https://msdn.microsoft.com/en-us/library/hh975440.aspx – Meyer Denney Mar 10 '15 at 18:05