Confusion over maxJsonLength default value

前端 未结 3 2080
清酒与你
清酒与你 2021-02-14 03:53

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

3条回答
  •  长情又很酷
    2021-02-14 04:30

    There are two defaults for MaxJsonLength depending on how JavaScriptSerializer is created.

    2 097 152

    It is 2097152 when serializer is created directly. Relevant code is:

    public class JavaScriptSerializer {
        ...
        internal const int DefaultMaxJsonLength = 2097152;        
        ...
        public JavaScriptSerializer(...) {
            ...
            MaxJsonLength = DefaultMaxJsonLength;
        }
    }
    

    102 400

    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.

提交回复
热议问题