title: Asp.net - Session Time out (close confirm message)
body: <p>Implemented this for session time out which is working fine:</p>
  
  <pre><code>var sessionTimeoutWarning = "1";
  var sessionTimeout = "2";
  var timeOnPageLoad = new Date();
  var sessionWarningTimer = null;
  var redirectToWelcomePageTimer = null;
  //For warning
  var sessionWarningTimer = setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
  //To redirect to the welcome page
  var redirectToWelcomePageTimer = setTimeout('RedirectToWelcomePage()', parseInt(sessionTimeout) * 60 * 1000);
  
  //Session Warning
  function SessionWarning() {
      var minutesForExpiry = (parseInt(sessionTimeout) - parseInt(sessionTimeoutWarning));
      //var minutesForExpiry = "1";
      var message = "Your session will expire in another " + minutesForExpiry + " mins. Do you want to extend the session?";
  
      //Confirm the user if he wants to extend the session
      answer = confirm(message);
  
      //if yes, extend the session.
      if (answer) {
  
          //Clear the RedirectToWelcomePage method
          if (redirectToWelcomePageTimer != null) {
              clearTimeout(redirectToWelcomePageTimer);
          }
  
          var currentTime = new Date();
          var timeForExpiry = timeOnPageLoad.setMinutes(timeOnPageLoad.getMinutes() + parseInt(sessionTimeout));
          if (Date.parse(currentTime) &gt; timeForExpiry) {
                alert("Session expired. You will be redirected to welcome page");
              window.location = "../login.aspx";
          }
          else {
              timeOnPageLoad = new Date();
              sessionWarningTimer = setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
              redirectToWelcomePageTimer = setTimeout('RedirectToLoginPage()', parseInt(sessionTimeout) * 60 * 1000);
          }
      }
      else {
          timeOnPageLoad = new Date();
          sessionWarningTimer = setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
          redirectToWelcomePageTimer = setTimeout('RedirectToLoginPage()', parseInt(sessionTimeout) * 1);
  
      }
  
  }
  
  //Session timeout
  function RedirectToLoginPage() {
      window.location = "../login.aspx";
  }
  </code></pre>
  
  <p>Query: when the confirm message comes up, how can we track/enable that if user didn't clicked in 5 mins on that confirmation message then I want to close that automtically and display new popup that session has expired.</p>
  
  <p>Please advise</p>