Monday 3 September 2007

Validation of viewstate MAC failed... using AJAX UpdatePanel

Was getting the following error after a partial update of a component on an AJAX UpdatePanel:

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster

It seems the problem occurs because after the partial update the component include a GridView that used DataKeyNames. The use of DataKeyNames requires that view state is encrypted.
I think the error occurred because this encryption was only taking place after the partial postback.

The solution seems to be to always have view state encrypted ~ a page directive.


viewStateEncryptionMode ="Always"