Set aspnet:MaxHttpCollectionKeys Programmatically

2019-04-08 06:43发布

问题:

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?

回答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



回答2:

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."



回答3:

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.