You will need to use Session_End(). A user can simply close their browser, and to them, they are now "logged off" - but nothing has alerted the server that they have logged off unless they clicked a "log off" button before closing their browser. So, once their session times out, the Session_End() event will be triggered and you can capture your logout in there.
How to determine a user logout in asp.net c#?
-
12-12-2021 - |
Pergunta
I have to maintain the user login and logout time in database. For login its easy but for logout , if I use Application_End ()
in global.asax
for logging. It gives me exception.
My Code in asax file:
Application_End()
{
HttpCurrent.Context.Session.Abandon();
LogUserLogoutTimeToDatabase();
}
Solução
Outras dicas
You're best and first bet would be a logout button in the application. After that you can use a Session timeout event with a very short session time.
Application_End is triggered when the application is shutting down but not during a server crash.
the best way to achieve this is , use onClick
event of logout button.
when user click on log out button , store that time in database
...
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow