Solved

Session_OnEnd Event Not Firing

Posted on 2014-02-25
7
324 Views
Last Modified: 2014-02-26
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
0
Comment
Question by:JB4375
  • 3
  • 2
  • 2
7 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 250 total points
ID: 39886151
0
 
LVL 1

Author Comment

by:JB4375
ID: 39886458
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?
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 39887327
The browser is independent of the server, and all communication between the two must be initiated by the browser. Hence, you cannot push a message box to the browser from the server. What I have done in the past is to add a <meta http-equiv="refresh"> tag to my page where the timeout value is set to be just a tad sooner than the actual session timeout value. This would perform an automatic refresh of the page. For your case, you wouldn't want this tag, but rather some Javascript to alert the user to the pending timeout. You could try doing something like (in your markup file):

<script>
    setTimeout(alertUserToTimeout, <%= Session.Timeout * 60000 %>);  <%-- Timeout is in minutes, so multiply by 60 for seconds, and by 1000 for milliseconds, which is what setTimeout expects --%>

    function alertUserToTimeout() {
        alert('Your session is about to expire!');
    }
</script>

Open in new window

0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 1

Author Comment

by:JB4375
ID: 39887698
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?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39887877
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
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39888351
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
0
 
LVL 1

Author Closing Comment

by:JB4375
ID: 39888843
Thanks for the help!!

Much appreciated as always,

JB
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question