微软在2011年12月29号发布的2011年最后一个更新让哥哥为程序出现的异常头痛了一天. 这个异常在页面数据量小的时候并不会触发,只在页面数据量大的情况下才会出现,开始解决起来让人无从下手,最后才发现猫腻.

异常信息如下:

对象的当前状态使该操作无效。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.InvalidOperationException: 对象的当前状态使该操作无效。

源错误: 

执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。 
堆栈跟踪: 


[InvalidOperationException: 对象的当前状态使该操作无效。]
  System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() +2692482
  System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) +61
  System.Web.HttpRequest.FillInFormCollection() +148

[HttpException (0x80004005): URL 编码窗体数据无效。] 

...

解决方法如下: 

   Author:    

 Hi i found the solution, it is due to the recent Microsoft security update we are getting this error. Seems they have added a new method called 'ThrowifmaxhttpkeycollectionKeysexceeded' with default value 1000, which means postback can contain only 1000 items.


Just add the following to your web.config(2.0 and above)

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

 

ThrowIfMaxHttpCollectionKeysExceeded()
问题在这里.
出现这个异常的原因正是因为上年12月29号那次微软发布的最后一次非正常更新程序引起的.在这次安全更新中对于asp.net单次的提交量做了一个最大量限制1000,出现这个异常正是因为页面提交量超过了1000这个限制.这个可以在web.config中增加参数来更改:
<appSettings>
<add key="aspnet:MaxHttpCollectionKeys" value="5000" />
</appSettings>

 

 吭爹的微软

 posted on 2012-01-10 11:24  小胜  阅读(7636)  评论(7编辑  收藏  举报