How to increase 2 MB limit on AJAX JSON response with ASP.NET MVC

I'm having problems with an AJAX call when the response exceeds 2 MB. Everything that has a 2 MB response works fine. When the response exceeds 2 MB, my "success" method is never called.

My application is ASP.NET MVC2. I am making a call using a jQuery AJAX call:

$.ajax({ type: "post", data: ajaxData, url: ajaxUrl, success: updateItems, cache: false }); 

In my controller, I use the Json () action result method:

 public ActionResult GetItems(....) { ... return Json(packet); } 

When I watch a call to Fiddler, it returns with an HTTP 500 response.

I tried to set maxJsonLength in the Web.config file as shown here , but that does not seem to make any difference.

Any suggestions on how to allow a response through 2 MB?

Thanks in advance,
Skip

+4
source share
2 answers

You can add the following to web.config:

 <system.web.extensions> <scripting> <webServices> <jsonSerialization maxJsonLength="1000000000" /> </webServices> </scripting> </system.web.extensions> 
+3
source

I'm not sure if you are using your own server or if you are using a hosting solution, however, we recently encountered this, but with a limit of 30 MB. Anything more will not lead to methods of success. Therefore, if you are on a shared host, this option can be set to 2MB for you.

We fixed this by changing maxAllowedContentLength, as described here: http://www.webtrenches.com/post.cfm/iis7-file-upload-size-limits

+1
source

Source: https://habr.com/ru/post/1332828/


All Articles