?
Solved

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

Posted on 2008-11-04
4
Medium Priority
?
362 Views
Last Modified: 2013-12-17
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.  
0
Comment
Question by:mmingfeilam
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
dwaynecharrington earned 750 total points
ID: 22882006
0
 
LVL 6

Assisted Solution

by:M3mph15
M3mph15 earned 750 total points
ID: 22882608
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
 

Author Comment

by:mmingfeilam
ID: 22888343
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
 

Author Comment

by:mmingfeilam
ID: 22901733
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

807 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