4

I have several websites which get approximately 3000 pageviews in total per day, and I get this viewstate error roughly 5-10 times per day, caught in global.asax:

System.Web.HttpException: Unable to validate data. at System.Web.Configuration.MachineKeySection.GetDecodedData(Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Int32& dataLength) at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)

I have tried:

  • hard-coding the machine key in web.config for all websites
  • hard-coding the machien key in machine.config
  • adding items to the pages section of the web.config for all websites.

Machine key looks like:

<machineKey validationKey="key goes here" decryptionKey="key goes here" validation="SHA1" decryption="AES" />

Pages section looks like:

<pages renderAllHiddenFieldsAtTopOfForm="true" validateRequest="false"  enableEventValidation="false" viewStateEncryptionMode="Never">

The errors are not related to application pool recycling as best I can tell, as the pool is set to recycle at every 100,000 requests. I am not running a web farm or web garden. Quite often I get two or three of these errors in a row, as if a user is getting an error, going back, and then clicking the link again.

Anyone have any ideas?

Ben Williams
  • 113
  • 1
  • 6
  • Another variation on the exception popped up today, not sure if its related? System.FormatException: Invalid character in a Base-64 string. at System.Convert.FromBase64String(String s) at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) at System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) at System.Web.UI.HiddenFieldPageStatePersister.Load() – Ben Williams Apr 17 '10 at 21:14
  • Do you have ELMAH setup? http://dotnetslackers.com/articles/aspnet/ErrorLoggingModulesAndHandlers.aspx Might give you a bit more context around the exception? – lomaxx Apr 22 '10 at 12:23

1 Answers1

2

I have seen "random" ViewState errors before caused by slow internet connections. The slow connections would cause the page to be visibly rendered to the user, however it hadn't completely loaded. The user would then take action on the form and thus "random" issues would occur.

See if you can correlate the exception timestamps to specific pages being requested in the IIS logs. You could then try to re-create the low bandwidth scenario with something like Firefox Throttle.

Similar question below confirms my experiences and probably what your are seeing as well:

ASP.NET: Unable to validate data

Community
  • 1
  • 1
rick schott
  • 21,012
  • 5
  • 52
  • 81