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

后端 未结 29 3194
礼貌的吻别
礼貌的吻别 2020-11-21 06:43

I am using the autocomplete feature of jQuery. When I try to retrieve the list of more then 17000 records (each won\'t have more than 10 char length), it\'s exceeding the le

相关标签:
29条回答
  • 2020-11-21 07:21

    You can configure the max length for json requests in your web.config file:

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

    The default value for maxJsonLength is 102400. For more details, see this MSDN page: http://msdn.microsoft.com/en-us/library/bb763183.aspx

    0 讨论(0)
  • 2020-11-21 07:23

    It appears that there is no "unlimited" value. The default is 2097152 characters, which is equivalent to 4 MB of Unicode string data.

    As as already been observed, 17,000 records are hard to use well in the browser. If you are presenting an aggregate view it may be much more efficient to do the aggregation on the server and transfer only a summary in the browser. For example, consider a file system brower, we only see the top of the tree, then emit further requestes as we drill down. The number of records returned in each request is comparatively small. A tree view presentation can work well for large result sets.

    0 讨论(0)
  • 2020-11-21 07:24

    I suggest setting it to Int32.MaxValue.

    JavaScriptSerializer serializer = new JavaScriptSerializer();
    serializer.MaxJsonLength = Int32.MaxValue;
    
    0 讨论(0)
  • 2020-11-21 07:24

    if this maxJsonLength value is a int then how big is its int 32bit/64bit/16bit.... i just want to be sure whats the maximum value i can set as my maxJsonLength

    <scripting>
            <webServices>
                <jsonSerialization maxJsonLength="2147483647">
                </jsonSerialization>
            </webServices>
        </scripting>
    
    0 讨论(0)
  • 2020-11-21 07:25

    if, after implementing the above addition into your web.config, you get an “Unrecognized configuration section system.web.extensions.” error then try adding this to your web.config in the <ConfigSections> section:

                <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>
    
    0 讨论(0)
  • 2020-11-21 07:25

    For those who are having issues with in MVC3 with JSON that's automatically being deserialized for a model binder and is too large, here is a solution.

    1. Copy the code for the JsonValueProviderFactory class from the MVC3 source code into a new class.
    2. Add a line to change the maximum JSON length before the object is deserialized.
    3. Replace the JsonValueProviderFactory class with your new, modified class.

    Thanks to http://blog.naver.com/techshare/100145191355 and https://gist.github.com/DalSoft/1588818 for pointing me in the right direction for how to do this. The last link on the first site contains full source code for the solution.

    0 讨论(0)
提交回复
热议问题