Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maximum value for aspnet:MaxHttpCollectionKeys

Tags:

asp.net

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?

like image 201
naveen Avatar asked Nov 09 '12 10:11

naveen


1 Answers

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

like image 78
Tarek Ayna Avatar answered Oct 02 '22 19:10

Tarek Ayna