Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
    
are you running a multi server farm with more than one WFE? If so, have you made changes to web.config files on all WFE servers? –  Anders Rask Jul 24 '11 at 15:34
1  
i have a farm with two site collection. do i have to change all of the web.config files on all site collections on farm? for example remove the "remove session" tag from all of the site collections on the farm?if it's so, no i didn't do it.you test that by yourself? –  Jalali Shakib Jul 25 '11 at 9:37
    
WFE = Web Front End = physical server. If your farm consist of more than one server that runs IIS, you need to make sure your updates are pushed out to all web.config files. This is usually done with the SPWebConfigModification class. Editing web.config files should generally be avoided, also with this class since its still quite buggy, but with modules you pretty much have to... –  Anders Rask Jul 25 '11 at 11:06
    
Apart from the 'also' question at the end which we'd really prefer a new question for, I can't see what the question is here? What is the problem in Session_End? –  Alex Angas Jul 29 '11 at 0:13
1  
actually i ain't problem with the Session_End event since this event even not firing to make a problem for me. "Why isn't the session_end event in my HttpModule firing?" i figure it out with some other solution and i solved that. my intend was to know how much users are online and i want to do this with session_start and session_end by checking and adding user in session_start to application variable and removing user from the application variable on session_end event. thanks for the time you spend. –  Jalali Shakib Jul 31 '11 at 4:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.