回发期间“由于对象的当前状态,操作无效”错误


170

我有一个运行良好的aspx页面,但是突然我收到错误消息“由于对象的当前状态,该操作无效。” 每当回发完成。

堆栈跟踪为:

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

有人可以帮忙吗?


Answers:


281

有人在您的页面上发布了很多表单字段。最近的安全更新引入的新默认最大值为1000。

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

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

有关更多信息,请阅读这篇文章。有关Microsoft安全修补程序的更多信息,请阅读此知识库文章。



40

我没有在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>

有关更多详细信息,请阅读 Microsoft知识库文章

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.