setting jsonSerialization maxJsonLength in ASP.net Web.Config gives 500 error
Asked Answered
D

4

5

So, I keep getting the 500 - Internal server error page on my .net site when I set the maxJsonLength in my web.config.

I'm modifying the .config because even though I use MaxJsonLength = Int32.MaxValue on my vb.net JavaScriptSerializer, I'm still getting InvalidOperationException for a large dictionary I'm trying to transmit even though it's well below the 4GB the MaxJsonLength @ Int32.MaxValue allows or even the supposed 4mb default limit.

I'm using toolkitscriptmanager if that means anything.

<system.web.extensions>
    <scripting>
        <webServices>
            <jsonSerialization maxJsonLength="2147483647" />
        </webServices>
    </scripting>
</system.web.extensions>

this didn't help (actually, it also gives 500 error without above code)

<sectionGroup name="system.web.extensions" type="System.Web.Extensions">
    <sectionGroup name="scripting" type="System.Web.Extensions">
        <sectionGroup name="webServices" type="System.Web.Extensions">
            <section name="jsonSerialization" type="System.Web.Extensions" />
        </sectionGroup>
    </sectionGroup>
</sectionGroup>

heard this should help with InvalidOperationException, but it didn't. I took it out, and still 500 error.

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

Many thanks in advance!

Edit

Same problem, but his solution doesn't work for me. The last code he added also gives 500 error. Problem with <system.web.extensions> config group when upgrading to .NET 4.0

Doorplate answered 5/10, 2012 at 16:51 Comment(7)
if you inspect it firebug of chrome do you get an error message in the response with the 500 ? what makes you think the error is caused by the size of the response , there are many other reasons for 500 errorAutograph
Thank-you for replying. It gives no details in the response header, and the response is just the typical .net 500 error page. The error shows up when I put the jsonSerialization maxJsonLength line in. If I take it out, everything's fine except I can't get super huge JSON's which I need.Doorplate
weird, I use <jsonSerialization maxJsonLength="50000000"/> in my code all the time in web.config just like you did with no problem , is it in <configuration> ?Autograph
indeed. just trying to add the configsections causes 500 too. i'm trying all the solutions in that link in my editDoorplate
take the line out of the other code MaxJsonLength = Int32.MaxValueAutograph
will try, but it's 500ing for everythingDoorplate
try running on localhost and debugging for specific errors , when running on server you won't be able to get specific errorsAutograph
D
6

The problem for me was that I put the code in the beginning of the web.config. For some reason, putting it at the end worked.

Not an expert, so I have no idea why that worked.

It worked without the last two code sections that I tried to make it work.

Doorplate answered 5/11, 2012 at 15:3 Comment(0)
E
4

I agreed with Gracchus, I put this below block in end of web.config file

<system.web.extensions>
    <scripting>
        <webServices>
            <jsonSerialization maxJsonLength="2147483647"/>
        </webServices>
    </scripting>
</system.web.extensions>`
Eglanteen answered 17/7, 2013 at 6:21 Comment(2)
Make sure .ajax() call sync:true (duplicate attempts to call may end up your request)Eglanteen
You mean at the end of the configurationnode?Carriole
T
2

As none of above worked for me so I used this-

JsonResult result = Json(<your result>, JsonRequestBehavior.AllowGet);
result.MaxJsonLength = int.MaxValue;
return result;
Trephine answered 15/7, 2020 at 6:49 Comment(0)
H
1
<system.web.extensions>
    <scripting>
      <webServices>
        <!--<jsonSerialization maxJsonLength="50000000">
        </jsonSerialization>-->
        <jsonSerialization maxJsonLength="500000000">
          <!--50000000-->
        </jsonSerialization>
      </webServices>
    </scripting>
  </system.web.extensions>  

Above settings worked for me. Additionally i had to set the target framework of the website to .Net 4.0. This web config setting was giving me 500 error when the target framework was set to .Net 2.0

To change the framework, goto IIS and select Application Pool Right click on your website name and select Advanced settings. Here you can change the .Net Framework Version by clicking on the drop-down.

Also i had this setting at the bottom of the web config. Only for good luck :)

Hope this helps.

Homicidal answered 18/6, 2014 at 5:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.