Jump to content

Roryriffic

Members
  • Content Count

    4
  • Joined

  • Last visited

Community Reputation

0

About Roryriffic

  • Rank
    LAVA groupie

LabVIEW Information

  • Version
    LabVIEW 2013
  • Since
    2008
  1. Ahhh, I knew there was a technical term for the text associated with the status code; a "like" for your nugget of wisdom, good sir. This is also what I'm doing in my web service. Write your own string and set the response code - works like a charm for me.
  2. 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
  3. 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
  4. I saw that no one replied yet, so let me give it a try. I *sort of* ran into this issue. I'm not sure what you're using on the front-end, but I find that AJAX and Javascript work wonders when talking to a web service. For example, let's say I make a POST request (via AJAX) to one of my web service VI's. Then let's say that the VI throws an error. What I'll do is output my custom error text to a FP indicator called "statusMsg" as well as set the appropriate response code in the "Set HTTP Response Code" VI just before I exit the VI. (NOTE: I found that you cannot input an error into the "Set HTTP Response Code" VI or else the response code does not get set.) On the front-end, I can catch both the status message text AND the response code like this: $.ajax({ type: "POST", url: "/MyWebService/myPostMethod", // "data" can be anything (developer must define) // must be a corresponding input on LV web service VI data: dataToSendToLV, statusCode: { // here, catch specific reponse codes. redirect user to // the appropriate page. // these scenarios execute after the "error" section below 400: function() { window.location = "/MyWebService/badsyntax/"; } 401: function() { window.location = "/MyWebService/unauthorized/"; }, 403: function() { window.location = "/MyWebService/forbidden/"; }, 500: function() { window.location = "/MyWebService/error/"; }, 505: function() { window.location = "/MyWebService/unsupported/"; }, }, success: function(resp) { // when the web service returns with response code "200" // then execute this code alert(resp.statusMsg); }, error: function(resp) { // when the web service returns with response code other than "200" // then execute this code. NOTE that this executes before any // of the code in the "statusCode" section above alert(resp.statusMsg); }, }); // end $.ajax() Hope this helps.
×
×
  • Create New...

Important Information

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