ASP Classic and JavaScript check session status

I need help trying to figure out how to check the users session and see if they are all logged in.

The problem is that I have a static page that pretty much loads everything into "tabs" using jquery. So when a user moves a page, they never leave the same page they started on. Suggests my problem by trying to determine if they are all logged in or not when they click to update their information in their profile or whatever.

+2


a source to share


3 answers


Create some kind of arbional connection with the server when the user "translates the page". For example, when they click on the "tab" even though it doesn't have to use AJAX from the server to ping the server anyway.

Of course, what you really want to do is verify that the session is live, as all users can look at the Refresh button an hour before actually clicking.

You need both, and you will annoy users who take over your application and then find that they are out of date in some way, which would conflict with their experience on other sites.



In ASP, you have to store something in the object Session

to indicate that the user is logged in. Here is an example of the "I am logged in" page: -

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

      

You can now use this page as your targeting target. Ping before updating. If you get disconnected, I suggest you post the update data to the server wherever you are, but not to update. Request a username in the usual way with a redirect to a page that will then process these details.

+1


a source


I would recommend a slightly different approach to you.

Create server side data processing routines to return a special status, such as HTTP status 401, if the user is no longer logged in.



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

+1


a source


<TITLE>YourStaticPage.aspx</TITLE>
<%
  Session("username")="StealthRT"
  Session("email")="StealthRT@stackoverflowusers.com"
  Session("userid")=1
  Session("LastPageLoad")=System.DateTime.Now
%>

      

When you handle the button_click event for your Update Profile page, you should check if these variables are being saved in Session.Contents ("username") or Session.Contents ("LastPageLoad"), etc.

0


a source







All Articles