时间:2010-07-12 07:10:14

标签: asp.net-mvc

尝试通过传递参数来运行reportviewer但收到错误:

  

验证viewstate MAC失败错误(ASP.NET MVC)

尝试过以下但没有运气:

  1. 将机器密钥(http://aspnetresources.com/tools/machineKey)添加到web.config中的system.web标记

  2. 将enableEventValidation =“false”设置为web.config中的pages标记。

  3. 有什么帮助?

1 个答案:

答案 0 :(得分:2)

我们在很久以前遇到了同样的问题,经过大量搜索后,下面的代码解决了这个问题:

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);
}

我们已将它放在脚本标签的视图中,这不是很漂亮,但它有效......

进一步详情见: Strange unhandled exception from asp.net application - Validation of viewstate MAC failedhttp://www.codeproject.com/KB/viewstate/ViewStateCompression.aspx