Try adding this setting in web.config. I just tested this on .NET 4.0 with an ASP.NET MVC 2 project and with this setting your code doesn't throw:
<appSettings>
<add key="aspnet:MaxHttpCollectionKeys" value="1001" />
</appSettings>
That should work now (after you have applied the security update) to change the limit.
I hadn't updated my machine yet, so using Reflector I checked the HttpValueCollection class, and it didn't have the ThrowIfMaxHttpCollectionKeysExceeded
method:
I installed KB2656351 (update for .NET 4.0), reloaded the assemblies in Reflector and the method appeared:
So that method is definitely new. I used the Disassemble option in Reflector, and from what I can tell from the code it checks an AppSetting:
if (this.Count >= AppSettings.MaxHttpCollectionKeys)
{
throw new InvalidOperationException();
}
If it doesn't find the value in the web.config file, it will set it to 1000 in System.Web.Util.AppSettings.EnsureSettingsLoaded
(an internal static class):
_maxHttpCollectionKeys = 0x3e8;
Also, Alexey Gusarov tweeted about this setting two days ago:
And here is an official answer from a Q&A with Jonathan Ness (Security Development Manager, MSRC) and Pete Voss (Sr. Response Communications Manager, Trustworthy Computing):
Q: Is AppSettings.MaxHttpCollectionKeys the new parameter that
contains the maximum number of form entries?
A: Yes it is.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…