Validation of viewstate MAC failed

Yayan picture Yayan · Nov 4, 2009 · Viewed 9.3k times · Source

i am getting this exception help me how to solve this problem.

Error Time      : 20091104 151412
Error Message   : 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.
Source          : System.Web
StackTrace      : at System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError)
   at System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState)
   at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)
   at System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState)
   at System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState)
   at System.Web.UI.HiddenFieldPageStatePersister.Load()
   at System.Web.UI.Page.LoadPageStateFromPersistenceMedium()
   at System.Web.UI.Page.LoadAllState()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.bla_bls_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\87932190\f6393965\App_Web_slwxkxn3.2.cs:line 0
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Target Site     : Void ThrowError(System.Exception, System.String, System.String, Boolean)
Inner Exception : System.Web.UI.ViewStateException: Invalid viewstate. 
    Client IP: 172.16.153.71
    Port: 1466
    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 2.0.50727)
    ViewState: /wEPDwUKLTg3MDIzOTc1Ng9kFgICAw9kFgICAw9kFgJmD2QWBgIdD2QWAgIBDzwrAA0BAA8WBB4LXyFEYXRhQm91bmRnHgtfIUl0ZW1Db3VudAIUZBYCZg9kFioCAQ9kFhpmDw8WAh4EVGV4dAUDODU4ZGQCAQ8PFgIfAgUKMSAgICAgICAgIGRkAgIPDxYCHwIFDE5ZS1UgNjEwOTc1MGRkAgMPDxYCHwIFAzQwJ2RkAgQPDxYCHwIFA05ZS2RkAgUPDxYCHwIFClgtUHJlc3MgMjFkZAIGDw8WAh8CBRQzMCBPY3QgMjAwOSAwNDowMDowMGRkAgcPDxYCHwIFB1RFTEZPUkRkZAIIDw8WAh8CBQJJS2RkAgkPDxYCHwIFAkZHZGQCCg8PFgQeCUJhY2tDb2xvcgqmAR4EXyFTQgIIZBYCAgEPDxYCHwIFCkluIFByb2Nlc3NkZAILDw8WBB8DCqcBHwQCCGQWAgIBDw8WAh8CBRQwNCBOb3YgMjAwOSAxMTowMDowMGRkAgwPZBYCAgEPDxYCHwIFBkV4ZmFjdGRkAgIPZBYaZg8PFgIfAgUDODU1ZGQCAQ8PFgIfAgUKMiAgICAgICAgIGRkAgIPDxYCHwIFDE5ZS1UgODQ0Mzc0NWRkAgMPDxYCHwIFAzQwJ2RkAgQPDxYCHwIFA05ZS2RkAgUPDxYCHwIFClgtUHJlc3MgMjFkZAIGDw8WAh8CBRQyOSBPY3QgMjAwOSAwMzozMDowMGRkAgcPDxYCHwIFB1RFTEZPUkRkZAIIDw8WAh8CBQJJS2RkAgkPDxYCHwIFAkZHZGQCCg8PFgQfAwqmAR8EAghkFgICAQ8PFgIfAgUKSW4gUHJvY2Vzc2RkAgsPDx... ---> System.Web.HttpException: Unable to validate data.
   at System.Web.Configuration.MachineKeySection.GetDecodedData(Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Int32& dataLength)
   at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)
   --- End of inner exception stack trace ---

Answer

Paul Turner picture Paul Turner · Nov 4, 2009

If your server is running as part of a cluster (i.e. requests to your application are balanced across multiple servers), you must ensure that your machines are all configured to use the same machine key.

ASP.NET performs validation of ViewState data when a Postback occurs. This validation uses a private key (the Machine Key) to guarantee the integrity of the data. If you don't explicitly specify this key, it is generated for you. Different machines will generate different keys, and thus load-balanced requests may fail validation because they are validating against different keys depending on where the page is first served from and where the Postback is sent back.

This article tells you more about the purpose of machine keys as well as how to configure your servers.