maximum value for aspnet:MaxHttpCollectionKeys

2020-08-10 04:28发布

问题:

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?

回答1:

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.



标签: asp.net