好吧,这个话题在互联网上并不新鲜,我明白了。但我一直无法找到解决我的问题的解决方案。
问题是我不断在我的网站上发现这个异常。也许一天50次左右。 (请参阅下面的堆栈跟踪)
视图状态 MAC 验证失败。如果此应用程序由 Web Farm 或集群托管,请确保配置指定相同的validationKey 和验证算法。 AutoGenerate 不能在集群中使用。
我已经在 web.config 文件中预定义了一个机器密钥 - 这根本没有帮助。
然后我在某处读到,我可能是由于加载缓慢引起的错误,但我正在记录页面加载时间,当发生此错误时,没有什么值得警惕的。
一些人建议禁用视图状态解密,但正如许多其他人所写的那样,这并不是真正的解决方案。
有人知道该怎么做吗?
堆栈跟踪:
at System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError)
at System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState)
at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)
at System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState)
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.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.default_aspx.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Okay so this topic is not new on the internet, i get that. But i havent been able to find a solution that fixed my problem.
Problem is i keep catching this exception on my website. Maybe 50 times a day or so. (See below for stacktrace)
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
I have already predefined a machinekey in my web.config file - that didn't help at all.
Then i read somewhere that i could be an error caused by slow loading, but I'm logging page load times, and when this error occurs, theres nothing alarming.
Some ppl suggest to disable the viewstate decryption, but as a lot of other ppl write, thats not really a solution.
Anyone got any idea what to do?
Stacktrace :
at System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError)
at System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState)
at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)
at System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState)
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.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.default_aspx.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
发布评论
评论(1)
您需要将机器密钥添加到 web.config 中,
即
<系统.web>
原因是,在网络场中,您看到的页面可能由与您回发的机器不同的机器提供服务,并且视图状态/cookie 等的解密将不匹配,除非场设置的所有者与跨域的机器密钥相匹配。他的农场(不太可能)。在单服务器环境中,此密钥是自动生成的,但它并不重要,因为应用程序池始终知道自己的密钥
You need to add a machine key into web.config
i.e.
<system.web>
<machineKey decryption="AES" validation="SHA1" decryptionKey="875CF3B9B54E7058CE31EAFAB05AD19400FF3DA5CDB0D324D7433C4B233B350D" validationKey="5BC50363620E53177C8E7E81BE1CF13141F860C5E41AF3EEEFC82AA37160E82D"/>
The reason is that when in a web farm the page you see may have been served by a different machine than the one you postback to and the decryption of the viewstate/cookies etc will not match up UNLESS the owner of the farm setup matching machineKeys across his farm (unlikely). In a single server environment this key is automagically generated but it never matters as the application pool always knows its own key