Pages

Wednesday, November 14, 2007

ASP.NET __VIEWSTATE in recorded web tests - Validation of viewstate MAC failed

I'm not a developer, so I wasn't sure what was happening at first. I got a new machine, but couldn't run recorded web tests on it. There were error messages when I tried to run the recorded web tests on the new machine that were recorded on the old machine. Here's how I figured out what was happening.

The original error message didn't make sense to me until later. It said "Validation of viewstate MAC failed. If the application is hosted by a web farm of cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster"

At first I thought something was wrong with machine.config or web.config. I searched for the error message and read this forum post about adding changing web.config to add entries to the pages tag:
validateRequest="false"
enableEventValidation="false"
viewStateEncryptionMode ="Never"

That didn't work, so I found the request where the errors happened and tried deleting the Form Post Parameters that referred to __VIEWSTATE=

That didn't work, so I read about __VIEWSTATE this article explained that Viewstate contains user entered information encrypted in a hidden POST form field so users don't have to re-enter information after moving to another page.

Then I recorded a web test to get the updated encrypted VIEWSTATE=/whGSTdfdbdjdfy and copied the updated value to the other web tests. I also found a post that tells how to make the viewstate dynamic, but I only have Visual Studio installed on one machine now.

No comments: