how to detect MVC 4 session end

5.4k Views Asked by At

I'm developing my web application using MVC 4, I need to send an email to the user after session time out or after session has been ended by the user. Anyone have any idea how to detect the session end? Thanks

1

There are 1 best solutions below

3
On

You can use Session_End Event in Global.asax File

protected void Session_End(object sender, EventArgs e)
        {
           // Write your Logic
        }

Be patient. The event should be called, but not necessarily right after the timeout.

You could try from a Browser: Start a session,wait > 1 minute, do a Postback somehow

This should help to verify that the Timeout works and I think you will also see the SessionEnd happening at that time. Otherwise, just wait and start some other sessions. The system will come around o calling it sometime.

For more information

About Session_End Event in MSDN blog

Hope this helps