views:

62

answers:

3

What is the best way to determine "user logout" on IIS server in C#/Asp.Net?

I have an application where the logged in users can initiate long running activities on the server. Those activities need to be terminated when the user logs out.

It is not a problem when the user clicks on the logout, but how do I determine that the user has logged out for example in cases like the user's browser crash, user looses his connection etc.

A: 

This is not possible. The browser is running on a different computer, and will not inform the server when it crashes!

John Saunders
No. I do not intend to determine the browser crashes, rather I am trying to figure out how to terminate the user initiated long running activities on the server.
Varma
@Varma: you said, "but how do I determine that the user has logged out for example in cases like the user's browser crash". If that's not what you meant, then please edit your question appropriately.
John Saunders
+3  A: 

Make the application session timeout short and implement some kind of polling (AJAX request, for example) to the web application.

The polling takes care of maintaining the session and if the browser is closed without appropriate logout or it crashes, it ceases and the session times out soon.

Skrim
A: 

Some online banks like HSBC implement something like this by simply having a popup window appear after 1 minute, where no user response (e.g. clicking an OK button) closes the window and logs them out.

The technique I'd prefer is a JavaScript timer that redirects to the logout and then login page, firing an AJAX call to the server first to terminate your long running process for that user. Relying on Session End can give a bit of an annoying user experience in my view.

Chris S