Is there something like OnLeave() in razor pages?

For my app I need something like database of online users. I want to add user to database by OnGet() function. When user leave site his data should be deleted from database. I search for some event or whatewer which can run my deleting function. I´m sorry for my english and possibly wrong formulated question. Thanks for reply.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

There is no OnLeave() that would be of any use to you because it’s possible that the user shuts down their computer and so your code wouldn’t necessarily execute. Or your web site could crash unexpectedly and your code wouldn’t run.

Instead, have a script that runs once a day and deletes all users who haven’t visited in 24 hours. (Or have it run as often as you like, with whatever “purge” logic you want.)


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x