Link to home
Start Free TrialLog in
Avatar of JB4375
JB4375Flag for United States of America

asked on

Session_OnEnd Event Not Firing

We currently have a web app that times out after 20 minutes as intended. When this occurs I want to display a message box telling the user that the session has timed and out an to click OK to refresh the page.

I have the following VB code on the back end:

Imports System.Windows.Forms

Partial Class _Default
    Inherits System.Web.UI.Page
    Public Event OnEnd As EventHandler
    Public Property Timeout As Integer

    Public Sub Session_OnEnd()
        MessageBox.Show("Your session has timed out. Click OK to refresh your page.", _
            "Important:", _
             MessageBoxButtons.OK, _
             MessageBoxIcon.Exclamation, _
             MessageBoxDefaultButton.Button1)

        Dim result As Integer = MessageBox.Show("message", "caption", MessageBoxButtons.OK)
        If result = DialogResult.OK Then
            Response.Redirect("default.aspx")
        End If
    End Sub
End Class

And for testing purposes I’ve set the following entries in the web.config file to 1 minute for testing:

<sessionState mode="InProc" cookieless="false" timeout="1"/>

<authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="1"/>


The problem is that the event doesn’t seem to fire. I’m going into debug, executing one search and leaving the page alone, the nothing is happening. What am I missing here?

Thanks,

JB
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JB4375

ASKER

Interesting methods, but they seem a little over the top for what I'm looking for.

Also, from the code project link:
Note: In all the above scenarios, I am assuming SetTimeout method and session related variables will be reset whenever there is a post back. This may not work 100%, when there could be partial rendering and the SetTimeout method and session related variables may not be reset.

Isn't there a dependable method of simply capturing the event when it occurs, and then displaying a message box etc. as I've described above?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JB4375

ASKER

Right... I'm not concerned with alerting them before the session expires,

Just letting them know  when it has timed out so they aren't attempting to click around on the page before getting frustrated and then closing the window because they think something it wrong with the program.

I want the message box to inform them what has occurred, and clicking OK refreshes the page.

Questions:

In the code above, is session.timeout a system variable or can I just drop a number in there?

What would it look like for 20 minutes?
Session.Timeout is on the server, yes. It's value will be whatever you have configured it to be, the default being 20 minutes.

Yes, you can drop a number in there, but it would be better to use the variable so that the two values are in sync.

20 minutes would be: 20 x 60 x 1000 = 1200000
If you want to push the message from the session_end event of the server to the client browser, you can use SignalR.

http://www.codeproject.com/Articles/526876/AddingplusSignalRplustoplusanplusASP-NetplusWebFor
Avatar of JB4375

ASKER

Thanks for the help!!

Much appreciated as always,

JB