ASP.NET - get rid of Session variables when done

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

We have numerous pages that store datasets in Session. Sometimes these are
used for one page, sometimes for a few (ex. - search page looks up your info,
edit person page edits that info)

What i'd like is a way to get rid of these session variables when we no
longer need them. We originally trie putting cleanup code in Unload but then
realized unload gets called after every page hit, including postbacks, so it
wipes out data the active page is still using. That's not good

So not unload. Is there an event that tells me when the user is leaving this
page/URL for a different one? Then i could manually write the unload then

Alternately, is there a better way to do this?

My original idea was to use a FSM/workflow manager and have that control the
lifecycle of the session variables but we're near the end of the project and
don't really have time to implement that

Thanks

-baylor
 
btw, since i want the life cyle of these TDSes to be similar to the data in
view state, an obvious solution would be to put the datasets in viewstate
(assuming i knew how, which i haven't given much thought to). The issue is
that some of these TDSes are large and so i don't picture that approach as
being very efficient

-b
 
I dunno about efficiency, but you could access your page's viewstate via
protected virtual StateBag ViewState, inherited from Control. You
could access this as an ordinary dictionary.

I havn't built anything similar, but I would probably save my serialized
object in a database, and store an id in viewstate. Run a stored
procedure on an interval to remove any object that isn't in use. This
system could easily be expanded to a generic object cache storage. ;)
 
Back
Top