4

I am wondering if there is a way to change this value for a particular page, instead of setting it for the entire project. We are running into the limit, but only for a couple pages. Our project is using .NET 3.5.

For those who are unaware of what this variable is for, it is to get around this: http://support.microsoft.com/kb/2661403

Essentially if you have a lot of form keys (over 1000), you will get an exception when posting back to the page. You can get around this by specifying in your web.config:

There have been several questions about this limitation, such as this one: 'Operation is not valid due to the current state of the object' error during postback

However, I have not seen anything related to setting this for a specific page.

Community
  • 1
  • 1
Itison
  • 236
  • 2
  • 11

1 Answers1

5

No, that's not possible. It always checks the appSetting aspnet:MaxHttpCollectionKeys and if that is missing it will be set to 1000. You cannot override this because the reading of the setting and the default value is done inside an internal class.

Perhaps a better approach would be to build a form with less than 1000 items. Maybe in the form of a wizard. Or maybe by combining multiple values into a single data structure and deserializing it on the server.

Michiel van Oosterhout
  • 22,839
  • 15
  • 90
  • 132
  • Thank you for the response. I will accept this as the answer. Certainly the ideal scenario is to reduce the number of controls on the page. We will probably implement paging whenever this comes up and it makes sense in the UI. However, I was hoping for some sort of temporary solution we could perhaps apply to an individual page when the user reports it, or in the event that we really do not want to restrict the number of controls on a certain page. Since the web.config affects the entire project, we could potentially miss other issues. – Itison Jun 13 '12 at 01:03
  • I think a bigger question here is why the framework is ignoring `appsettings` configured under a location element. – Phil Cooper Jul 18 '14 at 08:04