【发布时间】:2009-12-31 17:27:54
【问题描述】:
对一个真正令人沮丧的错误的有趣看法。我有一个没有 runat=server 控件的 MVC 页面,只有一个表单,但在阅读我的错误日志时,我仍然在页面上收到“Validation of viewstate MAC failed”异常。
这里是抛出的异常:
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. ---> System.Web.UI.ViewStateException: Invalid viewstate.
Client IP: 10.XXX.XXX.XXX Port: 33791
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)
ViewState: /wEPDwUKMTc2MzIxNTAwOWRkLTq4ngVrnkwCLjQCKKiLdjGVFbs=
这是完整的堆栈:
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. ---> System.Web.UI.ViewStateException: Invalid viewstate.
Client IP: 10.XXX.XXX.XXX
Port: 33791
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)
ViewState: /wEPDwUKMTc2MzIxNTAwOWRkLTq4ngVrnkwCLjQCKKiLdjGVFbs=
Referer: http://www.shelfari.com/search/combine?Keywords=turn%20of%20the%20screw
Path: /search/Combine ---> System.Web.HttpException: Unable to validate data.
at System.Web.Configuration.MachineKeySection.GetDecodedData(Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Int32& dataLength)
at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
at System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError)
at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)
at System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState)
at System.Web.UI.HiddenFieldPageStatePersister.Load()
at System.Web.UI.Page.LoadPageStateFromPersistenceMedium()
at System.Web.UI.Page.LoadAllState()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.views_search_bookcombined_aspx.ProcessRequest(HttpContext context)
at System.Web.Mvc.ViewPage.RenderView(ViewContext viewContext)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<InvokeActionResultWithFilters>b__e()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
at System.Web.Mvc.Controller.ExecuteCore()
at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
尚不清楚为什么页面上会出现视图状态 - 我一直无法重现该错误,但它偶尔会出现在日志中。收到错误的用户往往是受信任的个人,不太可能手动操作视图状态。
生产环境是一个 webfarm,指定了 machineKey 配置,在所有机器上使用 validationKey 和验证算法。
有什么想法吗?
【问题讨论】:
-
如果您能提供完整的堆栈跟踪信息将会很有帮助。谢谢!
-
Levi,我已经内联添加了完整的堆栈跟踪。抱歉耽搁了,“忘记”了手头的问题……
-
只有当请求(表单或查询字符串)包含 __VIEWSTATE 键时,才应点击该代码路径。发生此异常时,是否可以准确查看客户端向服务器发送的内容?例如,您能否通过异常过滤器或 Application_Error 捕获这些异常并转储 QueryString 和 Form 的全部内容?
-
Levi,我必须更新服务器日志以获取更多表单内容。我可能需要一两天的时间来获得足够的数据来工作……所以我会在星期一回来报告。
-
自从我添加了额外的日志记录以来,此问题尚未重现...目前不知道该说什么。感谢所有提供帮助的人。
标签: asp.net asp.net-mvc viewstate