Getting asp.net to store viewstate in the session rather than bulking up the html

后端 未结 3 585
悲哀的现实
悲哀的现实 2020-12-18 00:53

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 wh

3条回答
  •  甜味超标
    2020-12-18 00:53

    You sure you want to do this? There are problems

    1. How do you keep individual pages apart? Sure, you can prefix the session state name with the page, eg. Session["/default.aspx-Viewstate"] but what happens when the user has multiple instances of a page open?
    2. So to solve that you put a hidden field with, say, a GUID in each page, which you then use as a key. So your session size grows. And grows. And grows. How will you know if/when you can remove things safely?

    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.

提交回复
热议问题