开发者

Validation of viewstate MAC failed 50 times a day

开发者 https://www.devze.com 2023-04-11 10:31 出处:网络
Okay so this topic is n开发者_运维百科ot new on the internet, i get that. But i havent been able to find a solution that fixed my problem.

Okay so this topic is n开发者_运维百科ot 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)


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

0

精彩评论

暂无评论...
验证码 换一张
取 消