ASP.NET has session states. So the one you should be interested is the Session_OnEnd event. But you can only use this inProc mode.
Refer to: http://msdn.microsoft.com/en-us/library/ms178583.aspx
Add this to Global.asax
public void Session_OnEnd()
{
//Perform your logic.
}