I'm hoping to get some clarification on the maxJsonLength property. Here is some background information.
I was having an issue with an AJAX response not being returned in a .NET web application using jQuery. When the user changed a drop down list, I manually built and displayed some HTML. The issue was that one specific selection returned a string that was about 140kB but it would not display in the browser. I narrowed the problem down to the length of the string being too long. In searching SO and elsewhere, I found that the issue could be resolved by manually setting the value of maxJsonLength in my web.config.
My confusion is about the default value of th maxJsonLength property. Some answers say it's 2097152 characters and reference this MSDN link. But others have said the default length is 102400 and reference this other MSDN link. In my testing, I've come to the conclusion that the default is 102400 bytes but I'm not sure of the reason for the other default value.
The MaxJsonLength property which can be set within the web. config of your application controls the maximum size of the JSON strings that are accepted by the JsonSerializer class. The default value is 102400 characters.
The MaxJsonLength property cannot be unlimited, is an integer property that defaults to 102400 (100k).
There are two defaults for MaxJsonLength
depending on how JavaScriptSerializer
is created.
It is 2097152
when serializer is created directly. Relevant code is:
public class JavaScriptSerializer {
...
internal const int DefaultMaxJsonLength = 2097152;
...
public JavaScriptSerializer(...) {
...
MaxJsonLength = DefaultMaxJsonLength;
}
}
It is 102400
when serializer is created by ASP.NET MVC (or older). Relevant code is:
public sealed class ScriptingJsonSerializationSection : ConfigurationSection {
...
private static readonly ConfigurationProperty _propMaxJsonLength =
new ConfigurationProperty("maxJsonLength",
typeof(int),
102400,
...);
...
[ConfigurationProperty("maxJsonLength", DefaultValue = 102400)]
public int MaxJsonLength { ... }
...
}
There are several places which assign serializer.MaxJsonLength
to this value — all of them are in ASP.NET-related code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With