ApplicationEvents.SessionEnd global system event - Get the session ID

Chris McCluskey asked on August 7, 2018 13:11

I want to execute some code after a user's session has ended. Ordinarily in an ASP.NET application I could leverage the Session_End method in the Global.asax file, and it's possible to get the Session ID of the session that has just ended within that, but we're advised against modifying the Global.asax file. Instead, it's suggested to use the ApplicationEvents.SessionEnd event in a custom module instead.

I'm getting a custom event handler to trigger when a user's session ends, however I can't figure out a way to get the Session ID of the session that has just ended within the method. Does anybody know? Is it possible?

Recent Answers


Peter Mogilnitski answered on August 7, 2018 13:29

You can use Kentico wrappers like SessionHelper.GetSessionID but HttpContext.Current.Session.SessionID should work.

0 votesVote for this answer Mark as a Correct answer

Chris McCluskey answered on August 7, 2018 13:47

Unfortunately both SessionHelper.GetSessionID() and HttpContext.Current.Session.SessionID are null when called within a method assigned to ApplicationEvents.SessionEnd.Execute, because the method is not being called in the context of a request.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.