Jump to content

Roryriffic

Members
  • Posts

    4
  • Joined

  • Last visited

Community Answers

  1. Roryriffic's post in Catch Session Timeout Events in LV Web Service was marked as the answer   
    Found the answer...  Maybe this is above and beyond, maybe nobody cares, but we're all friends here and I hope this helps somebody in the future...
     
    We can all agree that the easiest way to detect when the user's session ends would be for LV to expose the session timeout event, but LV does not do this (as of 2013sp1).  Furthermore, LV does not provide a mechanism for storing session handles/IDs and later polling them to see if the session still exists.  You can get the ID all day long, but you can do nothing with it (anybody see the two feature requests?).
     
    Thus, you have to get creative on the client side.  I'm using Javascript/jQuery/AJAX on the front-end to talk to the LV web service on the back-end, so that's the answer I'll describe.  Basically, to properly tell when a client's session ends you need to do two things: (1) give the client a [manual] link that will fire your custom "Logout.vi" AJAX method, and (2) you need to [automatically] catch the $(window).unload() event from the client to asynchronously launch that same "Logout.vi" AJAX command.  The $(window).unload() event is from jQuery and will fire when the user closed the browser or navigated away. Here's my pseudo-method to get the job done:
    <script> $(document).ready(function() { /************************************************* Sends a message to the server notifying the user navigated away from the page. /MyWebService/logout should map to your custom web service VI that eventually calls "Destroy Session VI" **************************************************/ $(window).unload(function() { alert("Hey! You're navigating away from my website and \ and I'm about to tell the server to close your session!"); $.ajax({ type: "GET", url: "/MyWebService/logout", async: true, success: function() { // do something on success(?) // not much you can do if user navigating away }, error: function() { // do something on error(?) // not much you can do if user navigating away } }). // end $.ajax() }); // end $(window).unload() }); // end $(document).ready() </script> So, yea, basically you'd put this in your HTML or Javascript file and make sure that your Logout.vi does what you need to to do to clean up the session.  In my case, I'm just logging the time to a database (for information) and destroying the session (for security).
     
    NOTE: If testing in Chrome, Chrome blocks alert() during unload events.
     
    Hope this helps someone
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.