If broken it is, fix it you should

Using the powers of the debugger to solve the problems of the world - and a bag of chips    by Tess Ferrandez, ASP.NET Escalation Engineer (Microsoft)

Validation of viewstate MAC failed after installing .NET 3.5 SP1

Validation of viewstate MAC failed after installing .NET 3.5 SP1

  • Comments 44

After installing .NET 3.5 SP1 you may get Validation of viewstate MAC failed exceptions when doing post backs on ASP.NET pages

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.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: 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.

Stack Trace:

[HttpException (0x80004005): Unable to validate data.]
   System.Web.Configuration.MachineKeySection.GetDecodedData(Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Int32& dataLength) +289
   System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +140

[ViewStateException: Invalid viewstate. 
	Client IP:
	Port: 34562
	User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; WOW64; .NET CLR 2.0.50727; .NET CLR 1.1.4322; InfoPath.2; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.590; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; Zune 3.0; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MS-RTC LM 8)
	ViewState: /wEPDwUKMTc2NzE0NzA0NmRkmWc0SFS8H55FfURfpUekG2KhS8g=
	Referer: http://localhost/MySite/Default3.aspx
	Path: /MySite/Default.aspx]

[HttpException (0x80004005): 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.]
   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
   ASP.default_aspx.ProcessRequest(HttpContext context) +4
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75



This will happen if you have specified an action on the forms element, and if the action is different than the page you are browsing to, i.e. in this case the page I am browsing to is Default3.aspx, but the action is set to Default.aspx (as you can see from the Path and Referer in the error message)

<form id="form1" runat="server" action="Default.aspx">


The reason this occurs after installing SP1 for .NET 3.5 is because prior to this service pack, the action attribute was ignored.   Now that it is no longer ignored, the post-back will actually post back to the action page, and of course the view state for Default3.aspx will not be valid for Default.aspx.

You’ve heard it before:)  this is not a bug, it’s a feature…  in this case that’s actually true…



Remove the action attribute, or change it to post to the right page if you want to have viewstate enabled.



  • PingBack from http://microsoft-sharepoint.simplynetdev.com/validation-of-viewstate-mac-failed-after-installing-net-35-sp1/

  • After installing .NET 3.5 SP1 you may get Validation of viewstate MAC failed exceptions when doing post

  • With respect solution does not sounds like "solution". what if i want to post data to different page with viewstate enabled..?

  • Jacob,

    If you want to move to a different page you would need to redirect or similar in that case and add the data you want to pass in a query string or cookie.    

    As viewstate is stored in the form (in a hidden form field) and "unpacked" at the beginning of each request, posting viewstate from one page to another will not work.  

    This has not worked before either, i.e. the action attribute has been ignored so if there was an action on the form field that has never worked.  The only difference now is that the action attribute is honored.    

    Manual posting (through code) has always given this error, if you post viewstate to another page...

    This post was meant to explain why you get this exception after installing 3.5 SP1 and what you can do to resolve the exception.  I agree that it is not a solution to "I want to post viewstate between pages".  However that is something that has never worked, by design.    

    If this is something that is essential to you I would urge you to either send feedback through visual studio (http://msdn.microsoft.com/en-us/library/zzszcehe.aspx)  or to open a support case and make a design change request.



  • I don't mean to encourage this (because it disables a security feature), but couldn't you use Page.EnableViewStateMac to disable view state MAC validation to work around this behavior?


  • I'm luck, not meet this error yet :)

  • I'm no web/app developer but after a "this isn't my job, I shouldn't have to deal with this" rant, I found that if you want to keep viewstate enabled and post to a different page, remove the 'action' attribute from the 'form' tag, and  then replace your html 'submit' control with an ASP.net button and set its 'PostBackUrl' property to the page that was previosuly specified in form's 'action' atribute.

    Hope that I understand the problem correctly and that this helps. Seems less drastic than: enableViewStateMac="false" viewStateEncryptionMode="Never" enableEventValidation="false"

    ...and so on.

  • I ran across this problem recently in dealing with MVC and asp.net/AJAX controls. No matter what I did, I could not get rid of the error. Even looking at the postback URL it looked the same as the referring URL. Of cource since I am using RealTime MSCharts, I needed the viewstate.

    The way I solved this problem, it to put all AJAX controls in an UpdatePanel. For some reason, the UpdatePanel (which posts back a partial view) posts back to the correct URL with the proper viewstate and voila, error gone!!!

  • Thanks for the post, solved it for me.

  • this is my solution.  I make a POST form, with the values i want.

    Private Sub PostResponse()

     Dim _msgResponse As String = String.Empty

     Dim _fldResponse As String = String.Empty

     _fldResponse += Me.getHiddenField("Amount", 1230.45)

     _fldResponse += Me.getHiddenField("Currency", 214)

     _fldResponse += Me.getHiddenField("AuthCode", "3242424")

     _fldResponse += Me.getHiddenField("ReferenceCode", "A453453")

     _msgResponse = String.Format("<form name=t id=t action={0} method=post>{1}</form>", URL, _fldResponse)


     Response.Charset = String.Empty

     Response.ContentType = "text/html"


     Response.Write("<script> t.submit(); </script>")


    End Sub

    Private Function getHiddenField(ByVal campo As String, ByVal valor As String) As String

     Return String.Format("<input name=""{0}"" type='hidden' value=""{1}"" >", campo, valor)

    End Function

  • Would this happen if say i had mypage.aspx and its action were set to mypage.aspx?var=

    Would the query string cause this to happen? I did have sp1 installed, although this was an .net 2.0 site

    i also tried unistalling sp1 but still get the error.

    I have another machine without sp1 on it - code works on there. So i assume the problem is with sp1 - any way to get my server back to the way it was without sp1 on it? Can i reinstall the 2.0 framework to restore it?


  • I just recently received this error (unable to reproduce however). It popped up from javascript (I am using Ajax/UpdatePanel) rather than the server throwing the error. Any ideas on how that could be caused? I checked my aspx page (only one of them) and the form tag does not have an action attribute.


  • I just started noticing this problem. It happens if my web page sits idle for 20 minutes or so and then you click on the menu item. The web site is only a one page aspx file so it's not a file name issue as Tess pointed out.

  • When i tried to integrate Google search box with asp.net 2.0 page, but service pack sp1 with 3.0 have installed in my  system, i am getting Validation of viewstate MAC failed error.

    plz advice to resolve the issues.

  • Thanks for this. Accidentally had a form action that wasn't meant to be there and would never have though to checked.

    Fixed the problem for me.

Page 1 of 3 (44 items) 123
Leave a Comment
  • Please add 1 and 7 and type the answer here:
  • Post