Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set different timeout for different session variables in ASP.Net

Is this possible to set different timeout for different session in ASP.Net?

Edited I mean that in the same page i have 2 session variable Session["ss1"] and Session["ss2"], is there possible to set timeout for each session? Or is there anyway to do the same like save session to cookie and set expire? Sry im just new to ASP.Net

like image 576
Hieu Nguyen Trung Avatar asked May 20 '11 08:05

Hieu Nguyen Trung


2 Answers

I wrote a very simple extender class that does that. You can find the source code here

Usage:

//store and expire after 5 minutes
Session.AddWithTimeout("key", "value", TimeSpan.FromMinutes(5));
like image 68
Alex from Jitbit Avatar answered Nov 18 '22 15:11

Alex from Jitbit


Set any timeout at login time, you can set different timeout for different users...

HttpContext.Current.Session.Timeout = 540;
like image 30
Govind Malviya Avatar answered Nov 18 '22 17:11

Govind Malviya