0

Currently implementing a web method (mvc framework 4.5.2) which is supposed to received a list of items as a parameter input as bellow:

 [HttpPost]
        public ActionResult GetDummyResults(DummyProductsDto productsDto)}
{
    var dummy = getMeSomeResults(productsDto);
    return Json(new { result = dummy }, JsonRequestBehavior.AllowGet);
}

When my list of products is less than 2K, the method works just fine, if it goes over 2K items, it crashes with the exception: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. Parameter name: input

I've tried a plethora of suggested tweaks for the web.config like ( <jsonSerialization maxJsonLength="2147483647"/> ) to no avail. Some others point to implement this inside the method: var serializer = new JavaScriptSerializer(); serializer.MaxJsonLength = Int32.MaxValue; but I guess this suggestion applies to issues with the response, not the request itself which seems to be the issue here. Any hint as to where should I be aiming at ? ... it seems to me, the request size of the input parameter to to be the culprit here, just not sure how to fix it.

-thanks,

Mike Gmez
  • 111
  • 3
  • 18

2 Answers2

1

Try these settings in your web.config:

<configuration> 
   <system.web>
       <httpRuntime maxRequestLength="2147483647"/> 
   <system.web>
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="2147483647"/>
           </webServices>
       </scripting>
   </system.web.extensions>
   <system.webServer>
       <security>
           <requestFiltering>
               <requestLimits maxAllowedContentLength="2147483647" />
           </requestFiltering>
       </security>
   </system.webServer>
</configuration>
0

I was able to implement ashiquzzaman code found over here: Can I set an unlimited length for maxJsonLength in web.config? He's basically overwriting MVC controller max json Deserializetion limit of 4 mb. (thanks)

Mike Gmez
  • 111
  • 3
  • 18