views:

2251

answers:

2

I've developed a website testing on localhost Cassini and it has always run fine, now when I deploy to my webserver I intermittently get the following error:

Global.Application_Error Error: Exception occurred during request: http://....blah.aspx 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) HttpApplication.RaiseOnError => EventHandler.Invoke => Global.Application_Error

This is being caught in my global.asax. I've searched around but can't find the cause. This exception is being thrown in extremely simple and small webforms. The site is not hosted within a webfarm.

2 pages seem to cause this error intermittently and one of them stores a bool in the ViewState, but it is not modified apart from that.

Has anyone come across this before?

+3  A: 

http://dotnetcoderoom.wordpress.com/2008/11/07/unable-to-validate-data-aspnet-error/

Cause: The basic reason of this is the difference of key while encrypting and decrypting the viewstate data. Suppose an asp.net rendered a page with key1 and saved the page state in view state, meanwhile asp.net’s key is changed to key2, now when some server side event will occur on page the viewstate will get decrypted and this error will occur as the old view state is now not valid due to a different encryption key.

It may occur when you open a page for along time and after that do some events on that.

Solution Fix the key in your web.config file, so that only one key is used to encrypt and decrypt the viewstate data.

For more information visit:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21321364.html

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q312906

FailBoy
+1 Good answer - here's a public implementation of the code on the technet page: http://www.developmentnow.com/articles/machinekey_generator.aspx
Paul Suart
I've added a machineKey into my web.config, and no errors yet, so hopefully this is the solution
Ciaran
Feel free to mark it as the correct solution ;)
FailBoy
I already have a machine key in my web.config and I still occasionally get this error. What do you suppose is causing it?
Slim
I'm not sure, I haven't encountered that problem before. I'll see if I can find anything
FailBoy
I have a machine key element in web.config as well and am still getting these.
RyanW
+1  A: 

Try adding a machine key to your web.config to see if that fixes the error

http://aspnetresources.com/tools/keycreator.aspx

Jon
I've added a machineKey into my web.config, and no errors yet, so hopefully this is the solution
Ciaran