more info here http://www.w3schools.com/a
Main Topics
Browse All TopicsI am using ASP and would like to be able to prompt users that are logged in that their session is about to expire and give them an option to extend their session before timing out. Is there a way to do that?
Please explain clearly.i am new to the asp.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
more info here http://www.w3schools.com/a
You can prompt the user and if user wants to keep session active you can send a dummy HttpRequest to the server like to a page like 'KeepSessionActive.asp'.
You can use xmlHttpRequest to that without refreshing the full page. http://www.scss.com.au/fam
Without refreshing the main page of the user's browser, you can take a look at remote scripting, in which you have a very small (1px x 1px) iframe that loads an asp page every 10 seconds that checks the time on the current session and the current timeout.
You'll have to set your session_onstart to make a new variable called ses_start which will hold the time when the session began
Then you'll have to create the remote scripting page with asp to check the difference between ses_start and the current time
Whenever you get to less than (1 minute maybe) before the session will timeout, call a function in javascript on the parent frame
quick code
global.asa
<SCRIPT language=vbscript runat="server">
Sub Application_OnStart
End Sub
Sub Session_OnStart
session("ses_start")=now()
session("reload")=""
End Sub
Sub Session_OnEnd
End Sub
Sub Application_OnEnd
End Sub
</SCRIPT>
remoteScript.asp
<%
dim dd
dd=datediff("s",session("s
Response.Write("<html><hea
if dd>(Session.Timeout-1)/60 then
Response.Write("<script>wi
end if
Response.Write("</body></h
%>
main page:
<html><body onload="callEvery()">
<script>
function someFunction(){alert("Your
function callEvery(){
document.getElementById('l
setTimeout("callEvery()",1
}
</script>
<iframe height="1px" width="1px" src="remoteScript.asp" id="littleFrame"></iframe>
</body></html>
Yeah there are two parts to this... You need <%Session.Timeout=30%> as your only ASP code and you need some javascript. For the sake of standards, I can't agree with rugg's answer
<script type="text/javascript">
<!--
function sessionMon() {
setTimeout("alert('Your session is about to expire.');",1800000);
// optionally direct them somewhere here with window.location.href = "some url";
}
// add this to the window's onload
window.onload = function() {window.onload(); sessionMon();};
// -->
</script>
Essentially the same thing just cleaner (in that you don't have to touch any other parts of the page source) and mine should validate.
As for session extension, you could use a little bit of AJAX (not as scary as it sounds) which just calls a background download of a file on the server... That extends the session with IIS and should keep things alive for when they do really post back.
function keepAlive() {
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xhr = new ActiveXObject("Microsoft.X
}
xhr.open("GET","someURL.as
xhr.send();
xhr.onreadystatechange=fun
if (xhr.readyState==4) {
sessionMon() ; // start the clock again
}
}
}
You would then need to modify sessionMon to ask the user if they really want to keep the session alive... Something like this:
function sessionMon() {
setTimeout("promptThem");"
}
function promptThem() {
if(confirm("Would you like to extend your session by 30 minutes"))
sessionMon();
else
window.location.href = "/"; // kick them out somewhere
}
I've not tested that, but it *should* work... =)
Be aware that 'setTimeout' (and 'setInterval', too) returns an ID for that timer, so you should really declare a page-level variable for that info:
pgTimerID = window.setTimeout("myfunc(
With the ID available, now you can give the user a way to stop the timer:
window.clearTimeout(pgTime
Business Accounts
Answer for Membership
by: Clever_BobPosted on 2006-12-21 at 16:38:36ID: 18184537
This allows you to set and return session information...
As for prompting users that their session will expire.... that is a little more difficult because of the nature of ASP. You will need to check their session details at the top of each page and provide an input field for them to set their new timeout etc.
<html>
<body>
<%
response.write("<p>")
response.write("Default Timeout is: " & Session.Timeout & " minutes.")
response.write("</p>")
Session.Timeout=30
response.write("<p>")
response.write("Timeout is now: " & Session.Timeout & " minutes.")
response.write("</p>")
%>
</body>
</html>