5

I wrote a HTTP Session State Module that handles my custom Session State Provider.
And you know Session_Start and Session_End will work in InProc mode and not in Custom mode.
So I want Global.asax to handle a Session_Start method (with my Custom session module and provider) to raise it to some initialisations on my application.

I found this Article to handle Sessoin_End Event in StateServer mode, but what about handling the Start Event?!

My Module's Start Event:

public sealed class MyCustomSessionStateModule : IHttpModule
{
    ...

    /*
     * Add a Session_OnStart event handler.
     */
    public static event EventHandler Start
    {
        add
        {
            _sessionStartEventHandler += value;
        }
        remove
        {
            _sessionStartEventHandler -= value;
        }
    }

    ...
}

My Web.config Module Configurations:

<httpModules>
    <remove name="Session"/>
    <add name="MyCustomSessionStateModule" type="CustomSessionStateServer.MyCustomSessionStateModule" />
</httpModules>

My Web.config Provider Configurations:

<sessionState  mode="Custom"  customProvider="CustomSessionStateStoreProvider" timeout="20">
    <providers>
        <add name="CustomSessionStateStoreProvider" type="CustomSessionStateServer.CustomSessionStateStoreProvider" />
    </providers>
</sessionState>

I wrote my module in a structure that the session_start will fire in AcquireRequestState's Begin Time.

/*
 * IHttpModule Member
 */
public void Init(HttpApplication app)
{
     ...

    // Handling OnAcquireRequestState Asynchronously
    app.AddOnAcquireRequestStateAsync(
        new BeginEventHandler(this.app_BeginAcquireState),
        new EndEventHandler(this.app_EndAcquireState));

     ...
}

private IAsyncResult app_BeginAcquireState(object source, EventArgs e, AsyncCallback cb, object extraData)
{
    ...
    if (_rqIsNewSession)
    {
        // Firing Sessoin_Start Event
        _sessionStartEventHandler(this, EventArgs.Empty);
    }
}

According to ASP.net Application Life Cycle The Session State must be available on AcquireRequestState event. but still i have null Session object in Gloabal.asax's Session_Start.
I wrote this module according to the Microsoft's .NET 4.5 framework SessionStateModule Source Code.

Mehdi
  • 5,435
  • 6
  • 37
  • 57
  • All the weird capitalisation distracts greatly from the actual question, for me anyway. – Grant Thomas Oct 08 '14 at 12:14
  • I think you may find your answer here: http://stackoverflow.com/questions/3410390/raise-session-onstart-event-from-custom-asp-net-sessionstateprovider-class – Stephen Kennedy Oct 19 '14 at 01:13
  • no. it is not my answer. i'm firing Session_Start on a custom HTTP Module not a SessionStateDataStoreProvider. – Mehdi Oct 19 '14 at 09:15
  • Can you clarify the reasons behind what you want to achieve. Why are you using session_start to do application initialization? – atom.gregg Oct 19 '14 at 09:44
  • it is a natural behavior of session module to handle session_Start and Session_End. i use it to add some user specific keys to the session object. – Mehdi Oct 19 '14 at 09:50

0 Answers0