Select to view content in your preferred language

Timeout

1050
4
Jump to solution
01-30-2012 05:23 AM
philippschnetzer
Frequent Contributor
I am using a simple login scenario which is built in to the index.html file.  When this page is accessed it uses a state to show the login screen, then when the user passes the authentication the state switches to the viewer.  Is there a way I can make the web app timeout after a period of inactivity - which would cause the page to refresh and automatically then force the user to log back in to the site?

I've tried using IIS to set timeout connections but those settings only pertain to asp.net as far as I can see and they do not affect the flexviewer app.  Is there some html code I can include in the index.html to make this happen?

Thanks!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
philippschnetzer
Frequent Contributor
Found the solution.  Scrap the above code I posted because it doesn't actually capture whether the user is active or not.  Decided to make it happen directly in flex.  So, here goes....

In ViewContainer.mxml add these import statements:

import mx.managers.SystemManager;    import mx.events.FlexEvent;    import mx.core.mx_internal;    use namespace mx_internal;



Then inside the creationCompleteHandler function add:
systemManager.addEventListener(FlexEvent.IDLE, userIdle);


and add this new function:
private function userIdle(e:FlexEvent):void {     if(e.currentTarget.mx_internal::idleCounter == 9000){ // 15 mins Elapsed while Being Idle!!      // do something when the application has been idle for 15 mins      navigateToURL(new URLRequest('http://www.this url works for me because it redirects the user to the login page/index.html'), '_self');     }    }


credit goes to this website

Also, the above code works well if you have a login required for the app, if not then you might need to tweak the code to do something other than a simple redirect to the main login page...

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus
Phillip,

   This is what I found on the subject that is closest to what you are looking for.

http://www.webmasterworld.com/javascript/4332132.htm
0 Kudos
philippschnetzer
Frequent Contributor
I couldn't make the code from the above link work for me....but I did find something else:

<script type="text/javascript">
var xScroll, yScroll, timerPoll, timerRedirect;

function initRedirect(){
  if (typeof document.body.scrollTop != "undefined"){ //IE,NS7,Moz
    xScroll = document.body.scrollLeft;
    yScroll = document.body.scrollTop;

    clearInterval(timerPoll); //stop polling scroll move
    clearInterval(timerRedirect); //stop timed redirect

    timerPoll = setInterval("pollActivity()",1); //poll scrolling
    timerRedirect = setInterval("location.href='www.google.com'",1200000); //set timed redirect

 
  }
  else if (typeof window.pageYOffset != "undefined"){ //other browsers that support pageYOffset/pageXOffset instead
    xScroll = window.pageXOffset;
    yScroll = window.pageYOffset;

    clearInterval(timerPoll); //stop polling scroll move
    clearInterval(timerRedirect); //stop timed redirect

    timerPoll = setInterval("pollActivity()",1); //poll scrolling
    timerRedirect = setInterval("location.href='www.google.com'",1200000); //set timed redirect

  
  }
  //else do nothing
}

function pollActivity(){
  if ((typeof document.body.scrollTop != "undefined" && (xScroll!=document.body.scrollLeft || yScroll!=document.body.scrollTop)) //IE/NS7/Moz
   ||
   (typeof window.pageYOffset != "undefined" && (xScroll!=window.pageXOffset || yScroll!=window.pageYOffset))) { //other browsers
      initRedirect(); //reset polling scroll position
  }
}

document.onmousemove=initRedirect;
document.onclick=initRedirect;
document.onkeydown=initRedirect;
window.onload=initRedirect;
window.onresize=initRedirect;

</script>


There are still some bugs...it doesn't seem to actually honour mouseevents...but you can easily set the time delay before a redirect occurs (so I just tell it to redirect to the index.html file which requires the user to log back in).  Could be much better (ie, little dialog window could appear telling the user the app is about to timeout...) but it will do for now...
0 Kudos
philippschnetzer
Frequent Contributor
Found the solution.  Scrap the above code I posted because it doesn't actually capture whether the user is active or not.  Decided to make it happen directly in flex.  So, here goes....

In ViewContainer.mxml add these import statements:

import mx.managers.SystemManager;    import mx.events.FlexEvent;    import mx.core.mx_internal;    use namespace mx_internal;



Then inside the creationCompleteHandler function add:
systemManager.addEventListener(FlexEvent.IDLE, userIdle);


and add this new function:
private function userIdle(e:FlexEvent):void {     if(e.currentTarget.mx_internal::idleCounter == 9000){ // 15 mins Elapsed while Being Idle!!      // do something when the application has been idle for 15 mins      navigateToURL(new URLRequest('http://www.this url works for me because it redirects the user to the login page/index.html'), '_self');     }    }


credit goes to this website

Also, the above code works well if you have a login required for the app, if not then you might need to tweak the code to do something other than a simple redirect to the main login page...
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Phillip,

   Great find. Make sure you make your post as the answer.
0 Kudos