10

In pages that have a viewstate that spans 10-15KB what would be an optimal value for

<pages maxPageStateFieldLength="">

in the web.config in order to reduce the risk of potential truncation leading to viewstate validation errors?

Chris Marisic
  • 32,487
  • 24
  • 164
  • 258

2 Answers2

1

The maxPageStateFieldLength doesn't limit the size of the view state, so it won't be truncated.

What it does is simply control how much of the view state will be placed in one hidden field. If the view state is larger than the maxPageStateFieldLength value the view state will simply be split into several hidden fields.

The default value is -1, meaning that the view state is put in a single hidden field, which is normally the most optimal.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • 3
    Yes which is why I asked for an optimal value that, I understand what it does. I've seen numbers as low as 40, 100 other instances of 1000, I haven't really seen any justification for any number as it seems like just arbitrary selections that aren't even powers of 2. – Chris Marisic Apr 06 '10 at 13:58
  • @Chris: The only reason that I see for using any other value than the default, is if you need to limit the size of the field values for some reason. If you have any need like that, the most optimal value would be the highest value that you can use. – Guffa Apr 06 '10 at 14:28
  • 4
    If I knew what that number was I wouldn't have posted this question. The reason this feature was added to ASP.NET back in 2.0 is that antiviruses/routers/proxies/etc can potentially truncate a single large hidden field which then correctly causes the pagestate to be invalid. Since this is a client issue that is not specifically reproducible is why I am seeking some type of consensus of what exactly is an optimal value for this that is not the default of -1. – Chris Marisic Apr 06 '10 at 14:58
  • 3
    @chris, this is the same question I want terribly to be answered. And I understand your frustration with the absence of such an answer. paging the experts... – nolisj Jul 08 '10 at 13:04
  • 6
    My solution was to just leave webforms and goto MVC2. – Chris Marisic Nov 30 '10 at 16:29
0

I am currently running into a problem where we are getting "HttpException Due to Invalid Viewstate" errors for only Firefox users. I am also seeing "System.Web.HttpException: An error occurred while communicating with the remote host. The error code is 0x80070001" exceptions paired up with the viewstate ones.

I believe that firefox has possibly got a max size on (possibly) hidden form fields - i need to verify this. I'm now looking to chunk up the viewstate using maxPageStateFieldLength to hopefully resolve (in the short term). The longer term solution is to refactor the aspx page to do a paging query for grid (instead of pulling down all the rows in one go - which is not a good thing to do).

IMHO, you should put in a maximum that is fairly large but not unlimited. I'd say 1MB is a start.

Dan Doyon
  • 6,710
  • 2
  • 31
  • 40
  • I've seen that behavior with view state that is only in the 10-15KB range which is why I was assuming that a chunking value would have to be small, probably 512bytes or something but even trying that low I've never seen those errors go away. It's just made me give up webforms and move all new development to MVC. – Chris Marisic Feb 15 '11 at 16:17
  • Thanks for post Chris. And correct this didn't fix the problem. I've seen posts about proxy servers truncating large hidden fields. I am also heading towards elimination of viewstate. It is a pain in the butt. Unfortunately, lots of legacy code and moving to MVC is uphill battle. Oh well, one can dream. – Dan Doyon Feb 19 '11 at 04:11
  • Good luck with eliminating viewstate I don't think it's possible if you use almost any type of controls, I tried that route with the release .NET4 supposedly making it possible and never got anywhere. For moving to MVC we've just been following a staggered transition as we overhaul any existing feature substantially it gets pulled out of the old projects and moved over. – Chris Marisic Mar 10 '11 at 16:20