web design
  • August 06, 2009 by David

    Session Logout redirect using Ajax

    PROBLEM:

    How to create a session control that automatically logs out the users when the session times out?

    In ASP, even when the session has timed out, you will still stay on the same page unless you request a new page. This can be an issue if the user is on a public computer.

    SOLUTION:

    We created a script with Javascript, AJAX, and timeout that loads every 5 seconds. The script calls a helper file which returns if the session state is true or false -> if the session state is true, it sends it back to javacript to run again in 5 seconds -> if the session state is false, it sends the user to the logout page.

    WHY AJAX?

    If we integrated the ASP session value directly into the javacript, the script would always think the session state is active since the ASP code will be built by the server before the javacript gets loaded.

    Ajax solves this ASP problem by requesting a different page to check for the session state and give that result back to the javacript.

    AJAX PAGE THAT CHECKS THE SESSION STATE
    ——————————————————————————

    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <%
    if len(session("OrgID")) > 0 then
     response.write "1"
    else
     response.write "0"
    end if
    %>
    
     

    One Comments

    1. tag cloud script says:
      August 22, 2009 at 2:02 pm

      Hello, could you tell us more about these things, you seems like an expert in this aspect.

    Leave a Comment

    • required  
    • required  
    •