18

I have a form that posts pretty big data and i get this error

[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

To resolve this I got this solution from StackOverflow itself

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

Now I would like to know the maximum valid value that could be set for aspnet:MaxHttpCollectionKeys. Is there any problem in setting this key to its max value?

Community
  • 1
  • 1
naveen
  • 53,448
  • 46
  • 161
  • 251

1 Answers1

11

You can see the implementation of MaxHttpCollectionKeys in the aspnetwebstack source on GitHub.

From the implementation it seems like these are the limits:

  1. MaxHttpCollectionKeys is an int, so it could have a max value of an integer (int.MaxValue: 2,147,483,647)
  2. Minimum value is 1
  3. Default value is 1000

This MSDN page recommends to not set MaxHttpCollectionKeys to a value too large as that would pose a security risk. enter image description here

naveen
  • 53,448
  • 46
  • 161
  • 251
Tarek Ayna
  • 340
  • 4
  • 10
  • Hello, I've the same problem with a page that has a very long ListView. About 400 rows and about 10 controls per row that continues to grow. I've set MaxHttpCollectionKeys to 4000 but it doesn't works anyway. Can you suggest me a value to set? Thank you – chenny Nov 04 '15 at 10:07