user4103496
user4103496

Reputation:

How to control session timeout after an ajax call

I have a pop up timer that notifies the user when there are 5 minutes left in their session. The user can then either let it tick down and be logged out or hit a button to refresh the session. The button triggers an ajax call to a web method. The server is set to have a timeout of 20 minutes. Everything works as expected the first time through, 15 minutes goes by and the timer comes up, the button is pushed the call is made. But after the first 15 minute period my timer shows up randomly from 5 to 30 minutes later(it still works correctly). For whatever reason the session.timeout is given a random number after the ajax call. I've adjusted my web method to include a "session.timeout =" as follows:

<WebMethod(EnableSession:=True)> _
    <Script.Services.ScriptMethod(UseHttpGet:=False)> _
    Public Function Check() As String
        If HttpContext.Current.Session("strValid") Is Nothing Then
            Return "expired"
        Else
            Session.Timeout = "20"
            Return "ok"
        End If
    End Function    

This is still causing random pop ups. If I use the session extender, and then switch to a different page within the app, the timer behaves as expected for the first popup and then back to randomness.

The method is called via javaScript, window.interval is not used.

Any idea how I can ensure the session timer is set to 20 minutes every time the session is refreshed?

Upvotes: 0

Views: 913

Answers (1)

Win
Win

Reputation: 62260

SessionState timeout is reset automatically on every page requests.

So, you do not need Session.Timeout = "20" line.

You need to have a client-side counter in JavaScript. Once Check method turns ok, you need to rest client-side counter to 0.

Upvotes: 1

Related Questions