Track login and logout even if browser is closed

I would like to track when a user logs into my ASP website and when they logout, but most users either go to another website or simply close their browser so there is no "logout" happening.

My way to solve this is to use onunload= inside the <body> tag and then call a javascript function that writes a record to my table with the sessionID, username and timestamp. The function would first check to see if a record already exists for that sessionID and if so, simply update the timestamp, if one doesn't exist, it would create a new record.

I think this would do what I am looking for but I do not know how to code writing to a DB from within Javascript. I know how to do so in ASP, but I don't want to call another ASP page because my site consists of many pages and if a user goes from one page to another, that would trigger an onunload= on each of them, If I called a logout.asp page, that would keep my user from going to their intended page within my site no??? That is why I figure I need to write the record to the DB from within javascript.

If I can simply call another ASP page to write the record and the user would still go to the intended page, please let me know and I will go that route. Thanks!

It is a company intranet application and if the user has javascript disabled, the site won't work, but if you feel session_OnEnd is the way to go, I'd be interested if you could provide some code for me to work with.

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…

Nothing in an HTTP request can be trusted, including HTTP headers and form data. A form token is a tool that can be used to guard against request forgeries (CSRF). This article shows an improved approach to form tokens, making it more difficult to…

The viewer will learn the basics of jQuery, including how to invoke it on a web page.
Reference your jQuery libraries: (CODE)
Include your new external js/jQuery file: (CODE)
Write your first lines of code to setup your site for jQuery.: (CODE)

The viewer will learn the basics of jQuery including how to code hide show and toggles.
Reference your jQuery libraries:
(CODE)
Include your new external js/jQuery file:
(CODE)
Write your first lines of code to setup your site for jQuery…