Question

I have defined session in my asp.net web application:

<sessionState mode="InProc" customProvider="DefaultSessionProvider" timeout="5">
  <providers>
    <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
  </providers>
</sessionState>

In the application, i am reading/saving data from/into session.

Session["userId"] = "UID123443";
string userId = Session["userId"].ToString()

My question is, that, if i read/write data to session, is the timeout reinitialized automatically?

If yes, is there any way of preventing this? For example, i need the session expire from 5 to 5 minutes, even if i am accessing data from it in the meantime.

Was it helpful?

Solution

I believe the timeout session is reset every time you do anything to the server. So causing a postback will reset the timer.

You could add a session variable called 'WhenToTimeout' which you set to 5 minutes from now. Only do it one time. Then when the current time is later than that - do what you need to do (log them out, ...)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top