开发者

ASP Classic and JavaScript check for session status

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 rea开发者_Python百科lly 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.


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.


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.


<TITLE>YourStaticPage.aspx</TITLE>
<%
  Session("username")="StealthRT"
  Session("email")="StealthRT@stackoverflowusers.com"
  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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜