How to Tackle : Validation of viewstate MAC failed error


While hosting your website there are situations when your website start showing the yellow screen of death when it is left for some ideal time.. The Error Message we get is : Validation of viewstate MAC failed error

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.

By Vishal Ranjan (vishalranjan2k11@gmail.com)

Solution:

Step 1:
Include the following line in the webconfig under :


<pages enableEventValidation="false" viewStateEncryptionMode="Never">


You can also include these things individually in every design page..
For example:


<%@ Page Language="C#" MasterPageFile="~/MasterHome.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" enableEventValidation="false" viewStateEncryptionMode="Never" Title="Untitled Page" %>


Step 2:
Now Include the following code inside :


<customErrors defaultRedirect="~/ErrorPage.htm" mode="On"/>


This is included in order to handle the error generated by the website in any case.. We have to include a .htm file which gets displayed whenever there is any error in the website…

Step 3:
The last step is to include validation and decryption key in the machinekey tag inside :
This can done by generating these keys from the following website:

http://aspnetresources.com/tools/machineKey
Or,
http://www.orcsweb.com/articles/aspnetmachinekey.aspx.
Or,
http://www.developerfusion.com/tools/generatemachinekey/

Add the generated keys in system.web section of the webconfig:

Example:


<system.web>
<machineKey validationKey="AutoGenerate,IsolateApps"
decryptionKey="AutoGenerate,IsolateApps"
validation="SHA1"/>
</system.web>


References:

dotnetwebforms.blogspot.in

http://blogs.msdn.com/b/tom/archive/2008/03/14/validation-of-viewstate-mac-failed-error.aspx


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: