views:

468

answers:

4

I have a page that has a really huge viewstate (>300KB). ...Yeah, I know. I've narrowed this anomaly down to one user control, but am having trouble determining what exactly that control is putting in there.

I've overridden SavePageStateToPersistenceMedium in the page, but am not great at working with the viewstate object passed in. Could I pass it in to some recursive function that would print out everything that's in the object?

I've tried using freely available viewstate decoders, but none have worked. I always get errors when it attempts to deserialize the viewstate.

I'm pretty much looking for a code snippet here.

Thanks,
Mark

Thanks for the traceing suggestion, esp. the trace.axd thing. But that still only tells me how big the controls are, it doesn't tell me what's in the viewstate. I want to be able to see if there are objects that I'm erroneously serializing to viewstate.

+1  A: 

I used to use trace.axd. It lists each request and dumps the contents of the viewstate. You'll have to enable tracing in web.config. If you've got lots of requests you'll want to update the cache size to more than 10.

Arnshea
A: 

Regarding the issue with viewstate decoders, you might have the viewstate encrypted. Check this post with comments/links on it: http://www.testingreflections.com/node/view/3424.

Update: try turning it off completely on the pages element in the web.config:

<pages ... viewStateEncryptionMode="Never" ... />

View the view state section in this msdn doc How To: Configure MachineKey in ASP.NET 2.0

eglasius
I removed the 'machineKey' setting from my web.config, but I still get "There was an error decoding the ViewState string: The serialized data is invalid." in my decoder.
MStodd
@MStodd added an update with more info, check it out to completely discard it being encrypted.
eglasius
A: 

I would just add Trace="true" to the page directive on your local machine. The control tree section will show you the viewstate size of each control.

wulimaster
+1  A: 

Fritz Onion's ViewState Decoder is what you need!

Andrei Rinea
I wish it would work, but I keep getting "There was an error decoding the ViewState string: The serialized data is invalid." in my decoder. This is even after I removed the 'machineKey' setting from web.config.
MStodd
Just tried v2.2 on this date, worked great!
Christopher Galpin