Wednesday, April 18, 2012

The URL-encoded form data is not valid

As a developer, it's the call you always dread.
"Hey, you know that web site that's been working great for years - it's broken."
We had that experience this last week with this error:
SOURCE: System.Web
LOCALPATH: ...
TARGETSITE: Void FillInFormCollection()exception: System.Web.HttpException: 
  The URL-encoded form data is not valid. ---> 
System.InvalidOperationException: 
Operation is not valid due to the current state of the object.
at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded()
at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding)
at System.Web.HttpRequest.FillInFormCollection()
--- End of inner exception stack trace ---
at System.Web.HttpRequest.FillInFormCollection()
at System.Web.HttpRequest.get_Form()
at System.Web.HttpRequest.get_HasForm()
at System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull)
at System.Web.UI.Page.DeterminePostBackMode()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
To prevent malicious attacks against asp.net sites, Microsoft in the patches for Bulletin MS11-100 limits the number of name-value pairs to 1000.
To increase this number you need to add this key to the website's web.config or to the machine.config(s) on your servers:
<add key="aspnet:MaxHttpCollectionKeys" value="3000" />

2 comments:

Roberto said...

Thanks a lot!

Magnus said...

Thanks a bunch!