后向传输期间出现“由于对象的当前状态,操作无效”错误

171

我有一个工作正常的aspx页面,但突然间在执行postback时出现错误“由于对象的当前状态不可行,操作无效。”

堆栈跟踪如下:

at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded()
at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding)
at System.Web.HttpRequest.FillInFormCollection()

有人可以提供帮助吗?


4个回答

283

某人向您的页面提交了相当多的表单字段。最近的安全更新引入的新默认最大值为1000。

尝试在您的web.config的<appsettings>块中添加以下设置。在此块中,您正在将MaxHttpCollection值最大化,这将覆盖由.net Framework设置的默认值。您可以根据表单需求相应地更改值。

<appSettings>
    <add key="aspnet:MaxHttpCollectionKeys" value="2001" />
 </appSettings>

欲了解更多信息,请阅读帖子。欲深入了解微软发布的安全补丁,您可以阅读此知识库文章


1
http://www.acumen-corp.com/Blog/tabid/298/EntryId/8/ASP-NET-Error-ThrowIfMaxHttpCollectionKeysExceeded.aspx - Soenhay
这个工作得很好...谢谢伙计!! - Amar Gadekar
谢谢@AmarGadekar,很高兴它对你有用。 - Devjosh

41

我的gridview没有应用分页功能,其中包含超过600条记录(带有复选框、按钮等),而且2001的值不起作用。你可以增加值,比如10000,并进行测试。

<appSettings>
<add key="aspnet:MaxHttpCollectionKeys" value="10000" />
</appSettings>

16

对于ASP.NET 1.1,这是因为有人发布了超过1000个表单字段,但设置必须在注册表中更改,而不是在配置文件中。应该在注册表中添加一个名为MaxHttpCollectionKeys的DWORD。

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\1.1.4322.0

对于 Windows 的 32 位版本,以及

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ASP.NET\1.1.4322.0

适用于 Windows 64 位版本。


6
如果您的堆栈跟踪看起来像以下内容,则表示您正在向服务器发送大量的 JSON 对象。
Operation is not valid due to the current state of the object. 
    at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32 depth)
    at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)
    at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)
    at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)
    at System.Web.Script.Serialization.JavaScriptSerializer.DeserializeObject(String input)
    at Failing.Page_Load(Object sender, EventArgs e) 
    at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
    at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
    at System.Web.UI.Control.OnLoad(EventArgs e)
    at System.Web.UI.Control.LoadRecursive()
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

为了解决这个问题,请在您的Web配置中更新以下密钥。如果您无法获取堆栈跟踪,请使用fiddler. 如果仍然无法解决问题,请尝试将数字增加到10000或更高。

<configuration>
<appSettings>
<add key="aspnet:MaxJsonDeserializerMembers" value="1000" />
</appSettings>
</configuration>

更多详情请阅读这篇微软知识库文章。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接