Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 353
jao Avatar asked May 26 '09 07:05

jao


People also ask

How long does ASP.NET session last?

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.

How long does session last MVC?

The default is 20 minutes.

Where is ASP.NET session stored?

Session data is stored as key/value pairs in the SessionStateItemCollection and can be accessed using the HttpContext. Session property.

What is Isession C#?

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.


1 Answers

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"];
like image 128
Rune Grimstad Avatar answered Oct 13 '22 00:10

Rune Grimstad