• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2504
  • Last Modified:

How to detect session timeout

I have a form that requires a user be logged in. Should the session timeout, I need to save whatever data is currently on that form. How do I detect a session timeout so I can save the data? If it makes a difference, this is a DotNetNuke website.
0
Russ Suter
Asked:
Russ Suter
  • 4
  • 4
  • 3
1 Solution
 
VICKRAMCommented:
You can make use of Session_OnEnd Event in the Global.asa file

See: http://www.w3schools.com/asp/ev_sess_onend_onstart.asp
0
 
Russ SuterAuthor Commented:
I have a Global.asax file but no Global.asa file in my website unless I'm not looking in the right place. Again, this is a DotNetNuke website so it may be a little different. Or, the Global.asax file might be what I'm looking for. Any ideas?
0
 
VICKRAMCommented:
Oops.. sorry I sent you the wrong link..
http://samples.gotdotnet.com/quickstart/aspplus/doc/globalasax.aspx
Look under "Application or Session-Scoped Events"

Similiar to Session_Start, you can write a Session_End
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
dstanley9Commented:
"Should the session timeout, I need to save whatever data is currently on that form."

You can do this with server-side code.  The form is all client-side, and you can't "force" a postback from the server.  If the session times out, the client never knows about it.   And there's no guarantee that the user still has the form open when the session times out.  


0
 
dstanley9Commented:
Sorry, I meant to say

"You CAN'T do this with server-side code"
0
 
Russ SuterAuthor Commented:
When I try to build I get the following error:

"The content in the application file is not valid."

The entire file reads as follows:

<%@ Application Inherits="DotNetNuke.Common.Global" Language="VB" %>

Sub Session_Start(Sender As Object, E As EventArgs)
  Response.Write("Session is Starting...")
  Session.Timeout = 1
End Sub

What's wrong?
0
 
VICKRAMCommented:
Like dstanley9 pointed out, if you are trying to save values from a form the session of which has timed out, then that is not possible... not even in the Session_End event..

Having said that, are you still interested in solving the error you are getting?
0
 
Russ SuterAuthor Commented:
I don't understand why this wouldn't be possible. Can't the server query the client for this information at session end?

Yes, I am still interested in solving the problem.
0
 
dstanley9Commented:
No.  HTTP is stateless, and web requests are only initiated from the client.  The server cannot forcibly get the data off of the client page.  It must be explicitly submitted.
0
 
dstanley9Commented:
You can, however, create a javascript timer that wanrs the user that their session is about to end and they should save the data to keep the session going:

http://ray.camdenfamily.com/index.cfm/2006/9/20/Using-JavaScript-to-warn-a-user-about-a-session-timeout

(it refers to ColdFusion but the JavaScript piece is what's important:

dim nMinutes = 9;
dim sTimeout = nMinutes * 60 * 1000;
setTimeout('sessionWarning()', sTimeout);
function sessionWarning() {
   alert('Hey bonehead, your session is going to time out unless you do something!');  
}

0
 
VICKRAMCommented:
Is what you pasted above the full global.asax code? If not please paste the full code..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 4
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now