0

In my project, when user logs in, then I make an entry in A table Called LogTable and show it to the Admin Page that this user is online. And when user clicks on the log out button, then I delete data of that user from the log table, so this user is not shown online to the admin.

Now the main problem is that if user will close his browser without clicking that button, then how to delete those data.

Or what can be other way to achieve it in the best way?

I want that if user logs in from one system and tries to login from another system, then firstly we show that you are logged in another system and if she/he clicks on retrieve, then her/his other login automatically logs out and she/he has to login again.

Shayan Shafiq
  • 1,447
  • 5
  • 18
  • 25
ArunPratap
  • 4,816
  • 7
  • 25
  • 43
  • 1
    Search for and learn **SignalR** – ASalameh Feb 22 '18 at 06:35
  • 3
    While these aren't exact duplicates, there is a lot of discussion about how to run an action when the user closes the browser [here](https://stackoverflow.com/q/13247848), [here](https://stackoverflow.com/q/287022), [here](https://stackoverflow.com/q/23632725), and [here](https://stackoverflow.com/q/1921941). But the consensus is there is no 100% reliable way. – NightOwl888 Feb 22 '18 at 06:35
  • I haven't written a website in the last 5 or 6 years, but back then, you had no way of knowing if the user closed the browser or simply navigated to a different website, even in client side. we used the session on end event in gloabl.asax for such things, meaning you would have to wait for the session to timeout. – Zohar Peled Feb 22 '18 at 06:49

2 Answers2

1

Integrate your c# with javascript, javascript detect browser close, if you want to delete your data from db then you have to make http request for deleting data in this function. Try to interate it or make xml ajax request when browser is closing.

$(window).bind("beforeunload", function() { 
return "write your code over here for deleting data."; 
})
radhey shyam
  • 759
  • 6
  • 9
0

I would suggest reading up on the ASP.NET life cycle here and here.

Usually, we store that information using Session state.

The session is created for each user individually and will be automatically destroyed after a certain amount of inactivity or after the user has moved away from the page.

You could possibly use Application state. But application state is shared among all users and persists until the last user has navigated away from the site.

I hope this helps :)

Shayan Shafiq
  • 1,447
  • 5
  • 18
  • 25
Levidoom
  • 74
  • 1
  • 11