How to send a large / multi-part JSON object without changing maxJsonLength?

In my current C # web application, I am requesting a JSON object from WebMethod, this JSON object exceeds the maximum JSONLength length. And the results:

InvalidOperationException: The string is longer than the value specified for the maxJsonLength property.

My current solution was to raise maxJsonlength(in Web.config) above the length of the JSON object, but now that I am porting the application to Windows Server (which does not seem to support this override). Is there a way to send a JSON object via ajax POST in parts? If this is what is the best solution, I was looking for a way to send data in several parts, but there is no clear solution.

+4
source share
1 answer

This is not a solution that works without editing maxJsonLength, but allows maxJsonLength to be modified in Windows Server.

Adding the following to my web.config allowed me to edit maxJsonLength.

<configuration>
  <configSections>
    <sectionGroup name="system.web.extensions"         type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
    <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
            <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere" />
            <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
            <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
            <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
        </sectionGroup>
    </sectionGroup>
    </sectionGroup>
  </configSections>
  ... 
</configuration>

I hope this helps someone else get down to a similar problem.

0
source

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


All Articles