Warning that Session about to Timeout

H

Harry Simpson

Got a web app that keeps the 20 sec session timeout default. Only deal is
the user doesn't know the session timed out till they submit the page. On
one page that i actually don't care if it times out i have a meta tag that
refreshes at about 18 minutes so the screen never times out.

On the other pages that i want to time out, i'd like to pop a warning that
the screen has timed out that will stay visible til the user clicks OK......

What's the best way to acheive this result?

Thanks
Harry
 
K

Kevin Spencer

Use a JavaScript function in the page that waits 15 minutes and pops up an
alert box.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
H

Harry Simpson

Suppose that's the only way to do it. Are you writing it in the html or
doing the registerscriptblock?

I'll search my Javascript book for some code to piece together.

Thanks!

Harry
MCSD
 
F

Felbrigg

I've used a session variable that I check for in the page load, if it is not
there, then its timed out.
 
H

Harry Simpson

The kicker is I want the user to be warned on an already loaded page. On
postback i'll know a session has timed out immediately.
 
K

Kevin Spencer

Hi Harry,

Let me save you some trouble. You need to use the JavaScript setTimeOut()
function. Define a function that pops up the alert box, and use setTimeOut()
to set the delay. It takes 2 parameters, the function name, and the number
of milliseconds to wait. Here's an example:

<script type="text/javascript><!--
function SessionAlert()
{
alert("Your Session will time out in 5 minutes");
}
setTimeOut("SessionAlert", 15 * 60 * 1000);
// --></script>

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
F

Felbrigg

Intresting idea. But why warn them what are they going to do. In my
systems I redirect them to the login page and give them a message telling
them why.
 
G

George Ter-Saakov

I have a better solution than a warning.
What about session that never times out if user has his browser window open.

Here is what i am doing

1. Somewhere on each page (usually in a footer ) i have <img
src="/transparent.gif" name="renewSession" width="1" height="1">

2. Also each page has a following javascript.
<script language="Javascript">
window.setInterval("renewSession()", 600000);

function renewSession()
{
document.images("renewSession").src = "/renewSession.aspx?par=" +
Math.random();
}
</script>

3. Have a renewSession.aspx which outputs the transparent gif 1x1 pixel.

Done. Notice that you need Math.random() to prevent caching. Also in
renewSession.aspc use Response.Expires = -1.

You can easily create UserControl which implements all that and make that
control as a part of your header, footer,... what ever you have on each
page.


George.
 
H

Harry Simpson

Thanks to all who responded!!

I do want the session to expire if not used but i also want the user to be
aware that is what's happening before they enter a lot of stuff and submit.
Here's the code i came up with that works well:

function warnuser()
{
if (confirm("There has been no activity for some time.\nClick 'OK' if you
wish to continue your session,\nor click 'Cancel' to log out.\nFor your
security if you are unable to respond to this message\nwithin 2 minutes you
will be logged out automatically."))
{
//post the page to itself
document.location.href = "Utilities.aspx"
}
else
{
document.location.href = "Default.aspx"
}
}

then in the body tag:
onload=setTimeout("warnuser()",1080000)

Harry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top