Link to home
Start Free TrialLog in
Avatar of rwhitlatch

asked on

Validation of viewstate MAC failed

INFO:  C# Asp.Net 3.5 Web Application, Windows Server 2008, SQL Server 2008

I am getting a (seemly) random error message reported by my users when they login to my web application or even when they are in my application and navigate to a new page.  The exception occurs in some place I cannot seem to find and trap, so the user sees the exception page.  The error reported in various forms report this:

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

I have done research about this, and let me clear up these points.  The application is NOT on a server farm and it does NOT have "invalid" form actions.  

The view state settings are:

"<sessionState  mode="SQLServer"  sqlConnectionString="{connectionstring}"  cookieless="false" timeout="1200" />"

And does seem to work.  I have looked at the application pool, but it has been set to only recycle at midnight.  

The stack trace is:

System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +106
System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState) +14
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +242
System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) +4
System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +37
System.Web.UI.HiddenFieldPageStatePersister.Load() +207
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +105
System.Web.UI.Page.LoadAllState() +43
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
System.Web.UI.Page.ProcessRequest() +80
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49

Besides this random error, the application works great.

Thank you
Avatar of pradyahuja
Flag of Australia image

I have had this problem.
but my application was running on web farm.
However, go to
and one of the solution is

try to add this string in <system.web> section of your web.config file :
<pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode ="Never" />

also have a look at
Avatar of Kumaraswamy R
Kumaraswamy R
Flag of India image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rwhitlatch


I will try those and report back.
I went to and used solution #3 and recieved reports from my users.  The amount of events went from 12 or so down to 2.  And those 2 I have traced down to improper URL's on my part.

Thank you.