6

In a bit of admin functionality for a particular site, I'm doing a particularly horrific post that necessitates a large amount of data to be posted. In order to make that happen, I had to add the Web.config appSetting:

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

However, I only want this large post to be possible under a particular set of circumstances. Is there any way to programmatically set this value?

Community
  • 1
  • 1
eouw0o83hf
  • 9,438
  • 5
  • 53
  • 75

3 Answers3

1

You could make the setting specific to a location by placing the appSetting under a location tag in your web.config.

http://msdn.microsoft.com/en-us/library/b6x6shw7.aspx

spender
  • 117,338
  • 33
  • 229
  • 351
  • 1
    I've done that and verified that the config setting propagates through to the running code (by checking the config value in a breakpoint), but I get the same model binding error as if the setting weren't there at all. Is it possible that MVC for some reason doesn't honor this setting under a `location`? – eouw0o83hf May 24 '12 at 20:20
  • 2
    @eouw0o83hf I'm having the same issue in a regular ASP.NET app I'm supporting. Moving it under `` causes the `InvalidOperationException` to happen all over again. – Mike Guthrie May 24 '12 at 20:23
1

Looks like it's not possible, per this answer:

https://stackoverflow.com/a/10753846/570190

"You cannot override this because the reading of the setting and the default value is done inside an internal class."

Community
  • 1
  • 1
eouw0o83hf
  • 9,438
  • 5
  • 53
  • 75
0

You could isolate the form in a separate website in a virtual folder, with its own web.config. Of course if you need shared state then this can get quite complex (but not impossible). So perhaps by looking at it like a separate 'web service' that just happens to be able to handle 2000 items might solve the issue.

Michiel van Oosterhout
  • 22,839
  • 15
  • 90
  • 132