Jump to content

Catch Session Timeout Events in LV Web Service


Recommended Posts

Hi all,

 

new to Lava, so (kindly) let me know if I screwed up my post :)

 

I have a multi-user web application controlled by a LV web service.  I keep track of all the users through the web service > sessions VI's.  This is pretty cool and works really great. I can give each user different levels of authentication, force them to use SSL, track where they go and when throughout the website, etc.

 

Now what I'd like to do is keep track of when their session expires.  Obviously I can provide a "Logout" link on the client-side which ultimately calls the "Destroy Session" VI, but I can't ensure that all clients will click the link to log out (e.g. how many times do you really sign out of gmail verse just close the browser?!)

 

What's the best way to catch the session timeout event that is specified during "Create Session" VI?  It appears as if I need a "LV Web Service Request" object to even call the Destroy Session VI, which makes matters much more difficult it seems. Is this even possible?

 

Thanks for the help

Link to comment

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

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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