我有一个表单发布相当大的数据,我得到这个错误
[InvalidOperationException: Operation is not valid due to the current state of the object.] System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() +2419334 System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes,Encoding encoding) +58 System.Web.HttpRequest.FillInFormCollection() +159 [HttpException (0x80004005): The URL-encoded form data is not valid.] System.Web.HttpRequest.FillInFormCollection() +217 System.Web.HttpRequest.get_Form() +104 System.Web.HttpRequest.get_HasForm() +9035903 System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +97 System.Web.UI.Page.DeterminePostBackMode() +69 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) +135
为了解决这个问题,我得到了this solution from StackOverflow本身
<appSettings> <add key="aspnet:MaxHttpCollectionKeys" value="2000" /> </appSettings>
现在我想知道可以为aspnet设置的最大有效值:MaxHttpCollectionKeys.将此键设置为最大值是否有问题?
解决方法
您可以在GitHub的
aspnetwebstack source中看到MaxHttpCollectionKeys的实现.
从实施看来,这些是极限:
> MaxHttpCollectionKeys是一个int,所以它可以有一个整数的最大值(int.MaxValue:2,147,483,647)
>最小值为1
>默认值为1000
这个MSDN page建议不要将MaxHttpCollectionKeys设置为太大,因为这会造成安全风险.