Is there a way to find out the age of an asp.net session?

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

+3
source share
1 answer

I don’t think, I think, but it would be easy to do it on my own. In global.asax, you can add code to the Session_Start parity handler, where you add a session variable that tells you when the session was created.

Something like that:

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 following these steps in the code:

TimeSpan sessionLifeTime = DateTime.Now - (DateTime)Session["SessionStartTime"];
+4
source

Source: https://habr.com/ru/post/1709068/


All Articles