How do I find out how old an asp.net (3.5) session is?
A session automatically ends if a user has not requested or refreshed a page in an application for a specified period of time. This value is 20 minutes by default. You can change the default for an application by setting the Session.
The default is 20 minutes.
Session data is stored as key/value pairs in the SessionStateItemCollection and can be accessed using the HttpContext. Session property.
Session is a State Management Technique. A Session can store the value on the Server. It can support any type of object to be stored along with our own custom objects. A session is one of the best techniques for State Management because it stores the data as client-based.
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"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With