Tuesday, August 4, 2009

Automatic logout

From within a MasterPage, insert the following script to automatically logout users from a site after a specified timespan.

<script language="javascript">
   __applicationPath = "<%=Request.ApplicationPath%>";
</script>

<script language="javascript">
  /function __logout(msg, loc ) {alert(msg); location.href = loc;}
  /function __startLogoutCountdown(){window.setTimeout("__logout('Login Expired: ================== \\nThis site uses a security feature that automatically logs you out from your session after 16 minutes.', '<%=Request.ApplicationPath%>/Logout.aspx');", 960000);};
</script>

At this point, you can collect and destroy the user's session from Logout.aspx