Q:

Adding an event handler to a changing session value in asp.net c#

Can I add an event handler to a session value in asp.net with c#? 
I'm planning to update the database when user logs in and logs out and I control login and logout with session values, but the session may end without a user click, like timeout, so I'd like to add an event handler to "isloggedin" session value.  

A:

you need to handle this in global.asax. 
protected void Session_Start(Object sender, EventArgs e) 
{
 //your code
}

protected void Session_End(Object sender, EventArgs e) 
{
 //your code
}

