views:

20

answers:

1

I have a session variable and it is set default time of 20 minutes... Is it possible to see the running time of that session variable (ie) say 14 min 35 sec..

+1  A: 

If you are already in the codebehind, your session will always be renewed to the specified timeout as the request has already been processed. The same goes for FormsAuthentication ticket, to some degree, depending on the sliding expiration settings.

The only valid use case for auditing session/ticket timeout is in an AJAX scenario.

Auditing session and/or forms ticket lifetime is a tricky proposition because you have to go to the server to access the httpOnly cookie in order to determine the timeout which, in most any scenario, results in refreshing the cookie/ticket leaving you with a catch 22 which results in a never ending session.

I have developed a solution to this problem using a custom HttpModule that exposes 2 virtual endpoints that returns a value representing the remaining life of the session/ticket. You can access these endpoints from javascript or managed code.

Find the implementation and example solution here: AsynchronousSessionAuditor

Sky Sanders