4

Trying to run the reportviewer with passing the parameter but receive error:

Validation of viewstate MAC failed error (ASP.NET MVC)

Have tried the following but no luck:

  1. added the machine key (http://aspnetresources.com/tools/machineKey) to the system.web tag in web.config

  2. set enableEventValidation="false" to the pages tag in web.config.

any helps?

p.campbell
  • 98,673
  • 67
  • 256
  • 322
user384080
  • 4,576
  • 15
  • 64
  • 96

1 Answers1

2

We had the same problem not a long ago and after a lot of searching the following code has solved the problem:

protected override object LoadPageStateFromPersistenceMedium()
{
    string viewState = Request.Form["__VSTATE"];
    LosFormatter formatter = new LosFormatter();
    return formatter.Deserialize(viewState);
}

protected override void SavePageStateToPersistenceMedium(object viewState)
{
    LosFormatter formatter = new LosFormatter();
    System.IO.StringWriter writer = new System.IO.StringWriter();
    formatter.Serialize(writer, viewState);
    string viewStateString = writer.ToString();
    ClientScript.RegisterHiddenField("__VSTATE", viewStateString);
}

We have put it in the view in script tags, which is not very beautiful, but it works...

Further details see: Strange unhandled exception from asp.net application - Validation of viewstate MAC failed and http://www.codeproject.com/KB/viewstate/ViewStateCompression.aspx

Community
  • 1
  • 1
apolka
  • 1,711
  • 4
  • 16
  • 23
  • yes.. not so beautiful.. but you know what?!.. who cares!.. it solved the problem anyway.. :) you are a legend mate!.. thanks again. – user384080 Jul 12 '10 at 22:16