I deployed an HttpModule that needs to do something in session_start and session_end events.
I think everything's just fine, because I enabled the session state and set it to "InProc" mode and defined the timeout and activate the "state service" in Central Administration and also removed the "remove session" tag from web.config in modules section. The session_start event works just fine but the problem is session_end event. Here's my HttpModule code:
private void session_Start(object sender, EventArgs e)
{
SPHttpApplication app = MyApp;
string ip = app.Request.UserHostAddress;
string userName = (app.User != null) ? app.User.Identity.Name : "";
OpsToTable(app, ip, userName);
}
private void session_End(object sender, EventArgs e)
{
SPHttpApplication app = MyApp;
string ip = app.Request.UserHostAddress;
string userName = (app.User != null) ? app.User.Identity.Name : "";
OpsToTable(app, ip, userName, TableOps.RemoveFromTable);
}
public void Dispose() { }
public void Init(HttpApplication application)
{
SPHttpApplication app = (SPHttpApplication)application;
MyApp = app; // adding HttpApplication to property for using in session_start and session_end events
if (app.Modules["Session"] != null)
{
SessionStateModule session = app.Modules["Session"] as SessionStateModule;
session.Start += new EventHandler(session_Start);
session.End += new EventHandler(session_End);
}
}
Also, how can I access the HttpApplication when i'm in the session_end or start events? I defined the property and add HttpApplication in Init event to it, maybe its because of this?