how to create a mechanism to notifi user his session has expired

hi,

whenever i go to my bank's website, and if the page is idled for a while, the next time when i clicked on it, it will tell me my session has expired.  can someone tell me programmatically how that's done.  

or even better would be that the page will change to show the session has expired, and that the user needs to login again.  
LVL 1
mmingfeilamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dwaynecharringtonCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
M3mph15Commented:
Hi,

What i have done for some of my projects is when the user logs in add a variable to the session.

Session.Add("[variablename]", [variable]);
You can add anything really, even jsut a simple string. Then for everypage in the Page_Load() check for that variable so:
string s = Session("[variablename]").ToString;
So if s is null then either the user hasn't logged in or the session has timed out so redirecdt them.

Hope this helps
-M3mph15
0
mmingfeilamAuthor Commented:
dwaynecharrington: i think you solution fits our need the best.  i want to modify it so that when it times out, as opposed to being redirected to a notification page, just have a javascript popup window, and when the user clicks on the ok button, redirects it to the default.aspx page.  but i want to make sure that the redirect really does reload/refresh the page so that any old session variables will be deleted (theoretically when session expires, these variables should be gone, but i am not sure).  
0
mmingfeilamAuthor Commented:
dwaynecharrington:

i made some modifications to the code you suggested:

// for session timeout
var elapsedTime = 0;
// set to the Session.Timeout value to notify users
// one minute after their Session times out.
var maxTime;
var oneSecond;
   
function SetTimeOut()
{
    var hfTimeOut = document.getElementById("hfTimeOut");
    var timeOut = parseInt(hfTimeOut.value);
    maxTime = (timeOut + 1) * 60;
    oneSecond = window.setTimeout("timeoutCheck();",1000);
}

// recursive function
function timeoutCheck() {
    elapsedTime = elapsedTime + 1;
    if (elapsedTime > maxTime) {
        //window.location = "SessionTimeOutNotification.aspx";
        alert("Session Expired, Browser Will Now Be Closed. Please Open A New Browser To Login.");
        window.open("","_self");
        window.close();
    }
    else {
      oneSecond = window.setTimeout("timeoutCheck();",1000);
    }
}

i noticed one problem, elapsedTime is never reset even if a user is active, normally, the session timeout is reset whenever there is a server-side request.  so the next question is, how do i notify this function of a timeout reset, which will take place server-side?

also, has anyone ever use the glabal.asax event handler for Session_End?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

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.