1

这是一个与这里的问题非常相似的问题,但由于现在已经四岁了,我想我不会继续添加它。我也收到错误

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

但这发生在标准 ASP.NET 应用程序而不是 MVC 中。我的应用程序创建了一个包含大量(和少数行)的单个数据表,并将其绑定到 GridView(实际上是 Telerik RadGrid——我假设差异并不显着)。然后在网格的 Render 事件期间发生错误:

Exception information: 
    Exception type: InvalidOperationException 
    Exception message: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)
   at Telerik.Web.UI.RadGrid.DescribeProperties(IScriptDescriptor descriptor)
   at Telerik.Web.UI.ScriptRegistrar.GetScriptDescriptors(Control control)
   at Telerik.Web.UI.RadCompositeDataBoundControl.GetScriptDescriptors()
   at System.Web.UI.ScriptControlManager.RegisterScriptDescriptors(IScriptControl scriptControl)
   at Telerik.Web.UI.RadCompositeDataBoundControl.RenderContents(HtmlTextWriter writer)
   at Telerik.Web.UI.RadGrid.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
...
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at ASP.commoncontrols_ccesdmarginals_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in d:\Websites\CCESD\CommonControls\CCESDMarginals.ascx:line 12
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at CCESD.Web.Controls.CCESDMarginals.Render(HtmlTextWriter writer) in d:\Websites\CCESD\CommonControls\CCESDMarginals.ascx.cs:line 121
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer)
   at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer)
   at System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Page.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at Telerik.Web.UI.RadAjaxControl.RenderPageInAjaxMode(HtmlTextWriter writer, Control page)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Page.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

我已经尝试<jsonSerialization maxJsonLength="2147483647"></jsonSerialization>在 web.config 文件中进行设置,但这并没有什么不同,考虑到我没有使用 Web 服务,这并不奇怪。我还尝试了以下 web.config 设置,但均无效:

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

另一个链接中的第二个答案(我可以在 web.config 中为 maxJsonLength 设置无限长度吗?)似乎总结了我的情况,但由于我没有使用 MVC,我不确定如何使用他们的答案。有没有办法以某种方式覆盖 GridView (或等效)的内部序列化过程,以便它可以处理任意大的表?

4

0 回答 0