views:

360

answers:

4

This is in regards to a situation where Session is used to store some temporary data - one example being information entered during a multi-step registration process.

If a website has a number of such sections - which wants to utilize the session as temporary data store for pages within the section, what is a good way of cleaning up the session when the data is no longer required, considering that the user may simply navigate away from the section so the pages themselves cannot be used for cleaning up.

[Edit] In my case, the prime drive for this is to reduce network traffic as session is stored out of proc, but same concern can apply for memory bound applications and performance in general. Also unexpected data in Session can easily lead to difficult to track bugs.

A: 

If you want to store bulk data you have following alternatives:

  1. Cache
  2. Database

It is not recommended to store large amount of data in the session.

Ramesh Soni
+2  A: 

Time should keep the session clean. Sessions should expire and in doing so nuke all their data. This is default behaviour.

I'll agree that storing too much data in a session is not a great thing for server-resources but as you know, it's sometimes a necessary evil. If you're really that bothered, consider moving your sessions off to SQL Server. It'll add a smidge of latency but you'll be able to handle far more users.

Oli
A: 

Why not store everything in the database? That's just cleaner.

Why? Well, most modern web apps hit the database over a dozen times for each pageview, so a few extra simple queries shouldn't impact performance significantly.

Having said that, there's nothing wrong with storing a lot of user-generated data in a session, especially if you're using file-based sessions.

Why? How much text can a single person possibly type into a registration form, really? Anything under 4000 bytes will take the same amount of space: one OS page!

Seun Osewa
A: 

You can design a multi-step registration process without using session storage or using the database to store the temporary data. You can design one .aspx page with multiple panels that you make visible one panel at a time. When the user finishes the last panel, you will still have access to all the previously filled-out controls.

Aheho