0

In have a web app where session has the idletimeoout, 2 hours. Now when the session is idle for 2 hours I need to send an email. How to I raise an event on session expire?

services.AddSession(options =>
            {
                // Session timeout is at 2 hours
                options.IdleTimeout = TimeSpan.FromHours(2);
            }); /
DS2020
  • 279
  • 1
  • 4
  • 20

1 Answers1

1

In your Global.asax.cs file you can add the event handler:

protected void Session_End(object sender, EventArgs e)
{
    // Send your email
}

Note that you may need to add something to the session to ensure that the end event is raised. You can ensure that this happens by adding a dummy variable when the session is created:

protected void Session_Start()
{
    Session["SessionID"] = Session.SessionID;
}
AGB
  • 2,378
  • 21
  • 37