views:

57

answers:

3

I am in need of some help with trying to figure out how to go about checking the users session and seeing if they are still logged in or not.

The problem being is because i have a static page that pretty much loads everything into "tabs" using jquery. So when the user navigates the page, it really never leaves that same page they started out on. Hints my problem in trying to determine if they are still logged in or not when they click on update their information on their profile or whatnot.

A: 
<TITLE>YourStaticPage.aspx</TITLE>
<%
  Session("username")="StealthRT"
  Session("email")="[email protected]"
  Session("userid")=1
  Session("LastPageLoad")=System.DateTime.Now
%>

When you are handling the button_click event for your 'update profile' page you should be able to check if those variables are still stored in Session.Contents("username") or Session.Contents("LastPageLoad") etc.

nvuono
A: 

I would recommend that you take a slightly different approach.

Design your server side data-handling routines to return a special status, such as HTTP status 401 if the user is not logged in anymore.

Then make your client side AJAX routines capable of handling this, i.e. by opening/showing your login screen, preferably without losing the data/context of the attempted operation.

thomask
A: 

Create some arbitary communication with the server when the user "navigates the page". For example when they click a "tab" despite it not needing from the server use AJAX to ping the server anyway.

Of course in reality you will want to check the session is live anyway after all the user could stare at the "Update" button from an hour before actually pressing it.

You need both else you'll annoy users who have been busily using your app then find they're somehow timed-out anyway which will be contrary to their experiences on other sites.

In ASP you would store something in the Session object to indicate that the user is logged on. Here is an example "Am I logged on" page:-

<%
Response.ContentType = "application/json"
If Session("LoggedOn") Then
   Response.Write "{loggedOn: true}"
Else
   Response.Write "{loggedOn: false}"
End If
%>

Now you can use this page as your ping target. Ping just before update. If logged off I would suggest that you post details for update to the server any where but not to action the update. Request user loggon in your usual way with a redirect to a page that will then action those details.

AnthonyWJones
Thanks for that, Anthony. I'll use that with a response.redirect() if they are already logged out. :o)
StealthRT
Doesn't that sort of defeat the purpose of AJAX, sending needless extra requests?
thomask
@thomask: The purpose of AJAX is to improve the user experience when using a Web application. Having an application __so__ disconnected from the server that it can timeout while the user is actually using it is __not__ a good experience. Having a tiny __asynchronous__ (the first A in AJAX) ping at appropriate points during usage keeping the server session alive has no impact on the users current experience. Yet it eliminates the issue with a session timing out due supposed inactivity.
AnthonyWJones