ASP.NET: Unable to validate data

2019-01-16 21:36发布

What is the cause of this exception in ASP.NET? Obviously it is a viewstate exception, but I can't reproduce the error on the page that is throwing the exception (a simple two TextBox form with a button and navigation links).

FWIW, I'm not running a web farm.

Exception

Error Message: Unable to validate data.

Error Source: System.Web

Error Target Site: Byte[] GetDecodedData(Byte[], Byte[], Int32, Int32, Int32 ByRef)

Post Data

VIEWSTATE:

/wEPDwULLTE4NTUyODcyMTFkZF96FHxDUAHIY3NOAMRJYZ+CKsnB

EVENTVALIDATION:

/wEWBAK+8ZzHAgKOhZRcApDF79ECAoLch4YMeQ2ayv/Gi76znHooiRyBFrWtwyg=

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.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)

~ William Riley-Land

8条回答
Animai°情兽
2楼-- · 2019-01-16 22:32

"a postback is stopped before all the viewstate loads"

I've had this exact problem before, and this was the cause.

Initially we disabled the ViewStateMac property (enableViewStateMac="false" in the page directive) to solve it, but this is not a true solution to the problem and can threaten data integrity. We ultimately resolved it by disabled our submit button until the page had completely loaded, and trimming the size of our viewstate by disabling it on some controls.

查看更多
Deceive 欺骗
3楼-- · 2019-01-16 22:32

I've found the root of this problem in my web site and I finally managed to solve it. This is not a direct answer to your question, but I wanted to share this little piece of information.

In the past I tried everything (including the solution proposed by Jeffaxe, above) but with no result, and I didn't want to set enableViewStateMac="false" (as Raelshark mentions above) to my page, because this just hides the problem.

What caused the problem in my case? The problem was caused by the use of the Intelligencia.UrlRewriter (Version 2.0 RC 1 build 6) module in certain pages of my web site. I was using some SEO friendly links and that was causing the ViewState validation failure. When I used "normal" links (instead of the SEO-friendly links) the problem disappeared!

I reproduced the problem a few times to make sure it was not a false alarm (I use ASP.NET 3.5).

I know that some of you may not use the above module, and still get this error, which implies that the cause is something else. At least, sharing this experience might be helpful to some.

查看更多
登录 后发表回答