0

I have an ASP.NET web application using MVC 4, jquery, and Telerik's Kendo controls.

I have the following on my webpage:

<input id="cmdSaveToFile" title="Save To File" class="button" type="button" value="Save To File" onclick="SaveToFile();" tabindex="2" />

However, if I set a breakpoint in my Javascript file where SaveToFile() is defined, the breakpoint does not get hit. This method is supposed to send an ajax request to the server which will then create a file and store it in a session variable for downloading later.

Error logs on the server cite this error:

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

I've looked at these SO questions for that specific error:

MaxJsonLength exception in ASP.NET MVC during JavaScriptSerializer

Can I set an unlimited length for maxJsonLength in web.config?

I've added the accepted answer's contents to my web.config but that did not fix the problem. I cannot programatically set the JsonResult.MaxJsonLength property because I have no idea what is happening between clicking on the button and the method I specified in the view file from actually executing. Using Visual Studio + IE I can't break anywhere; not in the controller and not in the JS.

If I use Chrome, in their dev tools' "Event Listener Breakpoints" I can get it to break on Mouse Up / Down / Click but all of the jquery that executes is completely unreadable to me. What could it be doing under the hood that would cause this error?

Edit To clarify, the webpage in question simply contains a textbox and 2 buttons: Save to File, and Close. If you click Save to File, the software writes the contents of the textbox to an RTF file and presents the file to the user for download. This textbox contains an error report after they've uploaded a file and attempted to parse it out. If I upload and parse a small file, it behaves correctly. It's only when I upload very large files which creates a large amount of errors that this no longer works (because the error report is too long for JSON)... But if my breakpoint in SaveToFile() doesn't get triggered then what the hell is it doing?

Community
  • 1
  • 1
sab669
  • 3,984
  • 8
  • 38
  • 75
  • If you're using jQuery, wouldn't it be a lot easier to not use inline events and add an event handler instead. – adeneo Oct 11 '16 at 19:09
  • Have you looked in the network tab to see what's being sent to the server? – JLRishe Oct 11 '16 at 19:10
  • @adeneo I will give that a shot, but I don't see how that'd fix it. – sab669 Oct 11 '16 at 19:12
  • @JLRishe Let me check... Takes about 10 minutes to process the file in order to test the behavior though; give me a bit... – sab669 Oct 11 '16 at 19:12
  • @JLRishe I do see a call to `SaveToFile()` on the networking tab, but if I click it, I just get "Server Error in MyApplication" and then it gives the details I quoted in my original question. The stack trace just points to an array of `System.Web` calls; `System.Web.HttpApplication.ExecuteStep()`, then a handful of `System.Web.Mvc` requests. The "top most" call is `System.Web.Script.Serialization.JavascriptSerializer.Deserialize()` – sab669 Oct 11 '16 at 19:25
  • @adeneo That didn't make a difference, nor am I sure how it'd be any easier to test in this case. – sab669 Oct 11 '16 at 20:18
  • If the problem is because the file size is to long, then this should solve it: set the maxRequestLength to a number large enough to handle your transfer. I think the number is in bytes (could be kb), not sure. That would be in your web.config – nocturns2 Oct 11 '16 at 20:58

1 Answers1

0

try setting this in your web.config app settings

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

EDIT:

<bindings>
  <basicHttpBinding>
    <binding name="YourBindingName" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="20000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="Transport"></security>
    </binding>
  </basicHttpBinding>
</bindings>
gmdev86
  • 164
  • 5
  • Unfortunately, this did not make a difference. – sab669 Oct 11 '16 at 20:03
  • in your bindings try and increase your buffer sizes: maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" – gmdev86 Oct 11 '16 at 20:07
  • If that doesn't work try adding the readerQuotas tag: – gmdev86 Oct 11 '16 at 20:21
  • I'll try those first thing tomorrow, don't have time to test it one more time before the end of the day. Thanks. – sab669 Oct 11 '16 at 20:28
  • Which node do these `` elements belong under? ``? And what is `YourBindingName` supposed to be? I have no idea where to find that info – sab669 Oct 12 '16 at 18:58