How to continuously check if a user is online (without reloading the page) using Ajax ? It happens sometimes that the user has opened his profile in two different tabs, and he logs out from one of the tab, so the other tab immediately should show the log in page...
As for checking if the person is online , you can use many technologies like long polling , web socket and simplest one is periodically checking with the server running one script.
For other part it can be done on the server side where you need to maintain some kind of in-memory map (if you have only one webserver otherwise you have to store in the db ) which contains the logged in user id and some random key generated by your client side code whenever some logs in
Map<string,List<string>> tracker = new Map<string,List<string>>();
whenever you log in just that the new random key to the tracker by finding his id in the map
tracker[userId].Add(random);
whenever user logs out from any place clear the tracker key
tracker.remove(userId)
Now as we are making periodic call from AJAX if the tracker map does not contain the userId it means he has logged out from some place.
if(!tracker.Contains(userId))
//user is logged out from some other place
create code to check the status if there is sesstion return ture and if no return false and then in each page using jquery ajax call that page where you check the status and using get method and check the returnd data from that page if its true then the user still loged in , if false then the user logged out and settimeout for your ajax code 5 second