I'm trying to get asp.net to store viewstate in the session rather than bulking up the html.
Now i've read that asp.net comes with the SessionPageStatePersister which can be used instead of the default HiddenFieldPageStatePersister to do this. I was wondering how i go about dropping it in?
This is what i've got so far: I think i need to create a PageAdapter that returns a SessionPageStatePersister from its GetStatePersister method, and somehow get the page to use this pageadapter. But Page.PageAdapter only has a getter, so i'm not sure how you set it.
See the 'remarks' heading here: http://msdn.microsoft.com/en-us/library/system.web.ui.hiddenfieldpagestatepersister.aspx
Thanks!
In order to use your custom PageAdapter class you have to register it with .browser file. You need to add (if you don't already have) a App_Browsers directory. Then add a .browser file with following XML
replace {Your adapter type} with your adapter type.
More information here
Hope this helps.
For what it's worth, here's the code i ended up using to solve the big-picture problem at hand: moving viewstate out of the html. Just pop this into your mypage.aspx.cs:
And for a super-simple way of using the SessionPageStatePersister, again put this in your mypage.aspx.cs:
You sure you want to do this? There are problems
If you insist on heading down this read then all you need to do is derive a class from page and override LoadPageStateFromPersistenceMedium() and SavePageStateToPersistenceMedium(). But you'll hate yourself and rip it out eventually.
Just make sure you have HTTP compression turned on at your server, and please, worry about something else instead.