Thursday, April 27, 2006

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.