Session_End event is not firing

Viewed 68

I'm trying to call a method which updates a row in a database table in my Session_End method. I've enabled session state in web.config in this way:

<sessionState mode="InProc" cookieless="false" timeout="1"/> 

I've run this and did nothing for more for a minute, but I don't see anything getting updated in the table, hence the Session_End method not getting fired. Any ideas what I could do or why is it not firing?

Here's some sample code

protected void Session_End() 
{
    loguseractivity("logout",userip,serverip);
}
1 Answers

If you do not save anything in the session the Session_End event will not fire. There must be something saved in the session atleast once for the Session_End event to fire

So in Session start below I am saving Hello in the Session_Start

protected void Session_Start(object sender, EventArgs e)
{
     Session["Movies"] = "Hello";
}

So after session gets over, the session end event will fire

Related