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

后端 未结 29 3196
礼貌的吻别
礼貌的吻别 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:45

    if you are still getting error after web.config setting like following:

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

    I solved it by following:

       public ActionResult/JsonResult getData()
       {
          var jsonResult = Json(superlargedata, JsonRequestBehavior.AllowGet);
          jsonResult.MaxJsonLength = int.MaxValue;
          return jsonResult;
        }
    

    I hope this should help.

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

    We don't need any server side changes. you can fix this only modify by web.config file This helped for me. try this out

    <appSettings>
     <add key="aspnet:MaxJsonDeserializerMembers" value="2147483647" />
    <add key="aspnet:UpdatePanelMaxScriptLength" value="2147483647" />
    </appSettings>  
    
    and   
    
    <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="2147483647"/>
      </webServices>
    </scripting>
    

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

    The question really is whether you really need to return 17k records? How are you planning to handle all the data in the browser? The users are not going to scroll through 17000 rows anyway.

    A better approach is to retrieve only a "top few" records and load more as required.

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

    You can set it in the config as others have said, or you can set in on an individual instance of the serializer like:

    var js = new JavaScriptSerializer() { MaxJsonLength = int.MaxValue };
    
    0 讨论(0)
  • 2020-11-21 07:46

    Solution for WebForms UpdatePanel:

    Add a setting to Web.config:

    <configuration>
      <appSettings>
        <add key="aspnet:UpdatePanelMaxScriptLength" value="2147483647" />
      </appSettings>
    </configuration>
    

    https://support.microsoft.com/en-us/kb/981884

    ScriptRegistrationManager class contains following code:

    // Serialize the attributes to JSON and write them out
    JavaScriptSerializer serializer = new JavaScriptSerializer();
    
    // Dev10# 877767 - Allow configurable UpdatePanel script block length
    // The default is JavaScriptSerializer.DefaultMaxJsonLength
    if (AppSettings.UpdatePanelMaxScriptLength > 0) {
        serializer.MaxJsonLength = AppSettings.UpdatePanelMaxScriptLength;
    }  
    
    string attrText = serializer.Serialize(attrs);
    
    0 讨论(0)
提交回复
热议问题