Deserialize the EventValidation object

1.1k Views Asked by At

I am trying to serialize and deserialize the event validation store. I have used code on MSDN to do the same with the viewstate. I cannot seem to get the data out of the EventValidation object.

System.Web.UI.LosFormatter los = new System.Web.UI.LosFormatter();
var t = los.Deserialize("/wEdAAXD48AAvF6Ff7P5UOQbT3VqkrDKlMWdnNXfGOHHYL4xn7VF+rYDddmo2pWyOYlEzR9ytSa0+vS8Kw5xkFTTwf/ogY5mU3PIFIVTnINRkldVDi8fjE6FJuo5OYrccfM1phFxAalSeL3MjHSQK44wYPDs")
HashSet<object> h = new HashSet<object>();
foreach (object d in t)
{
   DoSomething()
}

System.Web.UI.EventValidationStore is the object type (?)

I have tried to use a hash set, a list, etc. I am new to this, and it is was out of what I know how do do, but would love to learn it.

The error I get is: "foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public definition for 'GetEnumerator'"

I could not find anything on MSDN about the System.Web.UI.EventValidationStore.

I apologize if this is a confusing post, I am just not sure how to ask it.

Update: I successfully deserialized one EventValidation base64 string, but others are proving to be elusive. The one in the code segment does not seem to work.

Summary: I need to be able to decode/deserialize and encode/serialize the eventvalidation base64 string in .NET.

1

There are 1 best solutions below

0
On

The __EVENTVALIDATION field structure is internal to ASP.NET and is subject to change. Trying to deserialize / serialize it is unsupported. The supported ways of interacting with it are via the Page's ValidateEvent and RegisterForEventValidation APIs.

What exactly are you trying to accomplish? Perhaps we can find a supported way of doing it.