Things that you should watch out when using SessionPageStatePersister

In my previous blogs i wrote about a very cool feature of asp.net called SessionPageStatePersister.

If you use / going to use this class to persist the view state in session you will have to be aware of couple of things:

  • The view state is managed as items in session plus a stack that holds the names of the keys in the session
  • The stack has a maximum size that can be configured through the configuration section (default is 9).
  • Each request create a new session view state item (Thus if exceeding the maximum it will also remove the first item)
  • If your application uses dialogs than you can come into a situation that the user is able to open several dialogs and do some posts which will eventually cause him to loose the view state of the original page (This scenario is very dangerous because you might not find it in your unit tests because you don't open a several dialogs or do many post back in them but the user WILL).
  • If you application uses frames than each frame request will create a new session view state item and as before it will remove items when reaching the maximum, you come into a situation that one of the frames will probably loose it session view state because other frames did post backs.

Recommendations:

  1. Don't use this persister on frames
  2. Don't use this persister in dialogs.
  3. Activate the session persister on specific pages.

I hope this helps you.

Things that you should watch out when using SessionPageStatePersister Things that you should watch out when using SessionPageStatePersister Reviewed by Ran Davidovitz on 9:57 PM Rating: 5

8 comments:

Anonymous said...

Ran,

I am working on page that is 4mb size when on the client, what makes the app to act too slowly as being displayed. I learned about this new feature in asp.net 2.0 that makes the size of this page about 2mb (that's cool). But there is a problem still persisting. After the information is displayed there is a delay that does not allow me to work inmediately on the page. For instance, menus cannot be displayed after several seconds.

Any help on this topic would be appreciated.

Thanks
Mario.

Anonymous said...

Hi,
Ran Davidovitz,
Please send ur email id,i wanted ask some doybts regarding Treeview Checkboxes - Check All - Javascript,please mail me as early as possible,i am in trouble,i think u can help me.Mu email id is vishwanath.bmca@yahoo.co.in

Anonymous said...

Where do I configure the stack size for the SessionPageStatePersister?

r said...

[system.web]
[sessionPageState historySize="10" /]

...
[/system.web]

(replace square brackets with <>)

Frédéric Malenfant said...

Wow you saved my life :-) We were using the SessionPageStatePersister and we lost the viewstate after some clicks (ajax-modalpopupextender) and with some iframes inside our page. With your help I finally found why! Thanks a lot.

Anonymous said...

How/where do you configure this "Activate the session persister on specific pages?

Anonymous said...

How/where do you configure this "Activate the session persister on specific pages?

Frédéric Malenfant said...

To activate:

in your "base page", (or a specific page), add this


Protected Overloads Overrides ReadOnly Property PageStatePersister() As PageStatePersister
Get
Return New SessionPageStatePersister(Me)
End Get
End Property

Then, in your web.config

under system.web

Powered by Blogger.