views:

492

answers:

3

I'd like to set the timeout on a specific Session Variable in a .Net web application, but leave other Session variables alone. Is this possible?

Example:

I have 5 Session Variables

Session(var1) Session(var2) Session(var3) Session(var4) Session(var5)

I want to set it so that Session(var1) through Session(var4) have a timeout of 8 hours (480 minutes), but Session(var5) has a timeout of 20 minutes. Can it be done?

+1  A: 

You would need to use an alternative to Session for storage. The Caching framework of asp.net is probably the closest alternative. Refer to Adding Items to the Cache.

Ken Browning
+1  A: 

You could provide your own implementation of HttpSessionStateBase your version would be aware of the different things it can store and change when they are flushed from the session.

Darryl Braaten
+1  A: 

You may implement this feature by creating timestamp field in this variable (or associated timestamp field). The timestamp will mark the time after which the variable becomes invalid. Of course you will have to handle the timestamp manually in your code (update it per hit, and remove it from session when it becomes invalid).

empi
How would I go about this? Can you detail with some code examples?
Eppz