11

Possible Duplicate:
Setting ViewStateUserKey gives me a “Validation of viewstate MAC failed” error

I have applied the solutions of the posts on StackOverflow but they did not work out for my problem.

The details of the problem is:

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.

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

[ViewStateException: Invalid viewstate. 
    Client IP: 131.155.68.60
    Port: 53999
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16
    ViewState: /wEPDwULLTIxNDQxNzQ5ODlkZDYHBedPRvEzZrTTrJvp9yAr5yfa
    Referer: http://rms.rextron.eu/login.aspx?ReturnUrl=%2fdefault.aspx
    Path: /login.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) +148
   System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +10959605
   System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +59
   System.Web.UI.HiddenFieldPageStatePersister.Load() +10959704
   System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +11043464
   System.Web.UI.Page.LoadAllState() +46
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11038983
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11038522
   System.Web.UI.Page.ProcessRequest() +91
   System.Web.UI.Page.ProcessRequest(HttpContext context) +240
   ASP.login_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\9ec5a6be\294c12de\App_Web_ptjxac-a.1.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +599
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171

I already tried to put this in the web.config:

<pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode ="Never">
Community
  • 1
  • 1
olidev
  • 20,058
  • 51
  • 133
  • 197
  • 1
    VERY Strange, I too had similar issue for 3 days and now i resolved it. 1. I had enabled forms authentication and had ssl false 2. but in my httpcookies tag I had requireSSL=true. Since in the Site.Master.cs it uses cookies to set the ViewStateUserKey, it was having issues 3. hence I was getting the error. 4. I modified this to false and restarted web app, now its all good. – Sundara Prabu Feb 16 '15 at 08:02

2 Answers2

11

I asked a similar question a while ago. Did you see this post? Another thing that helped me with this error was setting a machineKey. See this Microsoft Page about the problem and setting a Machine Key.

Community
  • 1
  • 1
Druid
  • 6,423
  • 4
  • 41
  • 56
  • If you have a web farm, you should also make sure the IIS site IDs on your sites match between servers. Somehow this number gets incorporated in the encryption of the ViewState. – Aaron D Apr 02 '14 at 19:02
9

I started having this problem today.

Long story short - I'd copied some of the form code from a similar page and forgotten to change the form action:

<form id="Form1" action="search.aspx" method="post" runat="server">

</form>

The form on results.aspx should have been:

<form id="Form1" action="results.aspx" method="post" runat="server">

</form>

I would recommend anyone else check this and also any inherits values before delving into config and other settings.

Justin
  • 91
  • 1
  • 1