Powered by Blogger.

Saturday, February 15, 2014

Validation of viewstate MAC failed error in Asp.Net



In this post we will discuss how to resolve the error "Validation of viewstate MAC failed" which sometimes comes in Asp.Net. Also you can check out some posts on:

- Repository pattern with code first approach in mvc4

- Constraints in SQL Server 2008

- Cookieless session in Asp.Net

Here is the full error mess

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.

Here the problem is with Machine Key field.

Solution:
Go to eggheadcafe Link and generate a Machine Key by click on the "Generate Me A Key!" button.

This will generate a Machine Key, Copy the whole thing and add it inside the <system.web> tag like below:

<system.web>

    <machineKey validationKey='E87A9D557279F86C841F2BA9A777CF91609F31D5D8F0F2079D7C00AB6A21A2E930463BE860C18D4526CBCB94904593B30979DC43DA4D247F828BE95557C1CA25'   decryptionKey='D17B35DFE5B1C60485A5964EAF154263DA1F95E4732B93DC' validation='SHA1'/>

  </system.web>

This should solve the issue.