在GridView的序列化过程中,我可以克服内置的JSON长度限制吗?

时间:2013-06-17 23:19:00

标签: json gridview serialization

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

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)

我已经尝试在web.config文件中设置<jsonSerialization maxJsonLength="2147483647"></jsonSerialization>,但这没有什么区别,鉴于我没有使用网络服务,这并不奇怪。我也尝试了以下web.config设置,一切都没有效果:

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

另一个链接中的第二个答案(Can I set an unlimited length for maxJsonLength in web.config?)似乎总结了我的情况,但由于我没有使用MVC,我不知道如何利用他们的答案。有没有办法以某种方式覆盖GridView(或等效的)的内部序列化过程,以便它可以使用任意大的表?

0 个答案:

没有答案