Officially the HttpSession event End is handled only in the Global.asax file, but I was wondering if is it there a way, although not officially (eg. Reflection) to handle the event in a different way.
i am not that expert on this matter, but i think you can use HTTPModule, as it allow to have access to all the events pf hte ASPX page, here is a link to nice article on creating HTTP Modules.
http://www.15seconds.com/Issue/020417.htm
hope this helps.
You could do something like this, but from what I have seen, it can be a nightmare:
public class MyHttpModule : IHttpModule, IRequiresSessionState
{
public void Init(HttpApplication app)
{
if (app.Modules["Session"] != null)
{
SessionStateModule session = (SessionStateModule) app.Modules["Session"];
session.Start += new EventHandler(Session_Start);
session.End += new EventHandler(Session_End);
}
app.PostRequestHandlerExecute += new EventHandler(Application_PostRequestHandlerExecute);
}
public void Dispose()
{
}
private void Session_Start(object sender, EventArgs e)
{
}
private void Application_PostRequestHandlerExecute(object sender, EventArgs e)
{
}
private void Session_End(object sender, EventArgs e)
{
}
}
There are multiple instances of your module, and they do not all have 'Session' in their list of loaded modules. I think there might also be multiple instances of the Session module, so the one whose End event you registered for in your first instance may not be the one that fires the End event later on.
This is not something that can be easily accomplished in an HttpModule, as the Session_OnEnd event may occur outside the scope of a request to the system. You are probably better off handling this through a custom Session State provider, where your Session management code is what triggers the Session_OnEnd event.