是的,关于这个特定错误有一百万个问题和线索,有许多有据可查的解决方案,我一定会尝试。但首先我想了解我的特定情况/环境的问题。
在我的情况下,这个错误似乎完全是随机的。我会几周都看不到它,然后有一天我会登录我的网站并得到错误。刷新页面,再次登录,没有问题。在事件之间的这段时间里,Web 服务器没有发生什么特别的事情。
这是另一件事,错误显示“如果此应用程序由 Web Farm 或集群托管......”,但事实并非如此。它只是一个单一的 Windows Server 2008。
所以,我知道一般的解决方案是在 web.config 文件中添加一组静态机器密钥 --- 但为什么这似乎是随机发生的,为什么它会发生在我位于单个 Windows Server 2008 上的站点上机器?
我正在使用 ASP.NET 4,我的网站是在 IIS 上运行的 Web 应用程序。
错误信息:
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.
堆栈跟踪:
[ViewStateException: Invalid viewstate.
Client IP: ##::##:##:##:##
Port: ##
Referer: http://myserver/login.aspx
Path: /login.aspx
User-Agent: Opera/9.80 (Windows NT 6.1; WOW64; U; en) Presto/2.10.289 Version/12.01
ViewState: /wEPDw...6OCX]
[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) +235
System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState) +14
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +274
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() +241
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +106
System.Web.UI.Page.LoadAllState() +43
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +8431
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +253
System.Web.UI.Page.ProcessRequest() +78
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.login_aspx.ProcessRequest(HttpContext context) +4
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75