views:

40

answers:

1

How do I find out how old an asp.net (3.5) session is?

+2  A: 

Not directly I think, but it would be easy to do it yourself. In global.asax you can add code to the Session_Start even handler where you add a session variable that tells when the session was created.

Something like this:

void Session_Start(object sender, EventArgs e) 
{
    // Code that runs when a new session is started
    Session["SessionStartTime"] = DateTime.Now;        
}

Then you can check how long the session has existed by doing the following in your code:

TimeSpan sessionLifeTime = DateTime.Now - (DateTime)Session["SessionStartTime"];
Rune Grimstad