尝试通过传递参数来运行reportviewer但收到错误:
Validation of viewstate MAC failed error (ASP.NET MVC)
试过以下但没有运气:
>将机器密钥(http://aspnetresources.com/tools/machineKey)添加到web.config中的system.web标记
>将enableEventValidation =“false”设置为web.config中的pages标记.
有帮助吗?
最佳答案 不久前我们遇到了同样的问题,经过大量搜索后,下面的代码解决了这个问题:
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 failed和
http://www.codeproject.com/KB/viewstate/ViewStateCompression.aspx