Oct 20, 2014 04:39 AM|mahdiahmadirad|LINK
I wrote a custom Session State HTTP module to handle many business policies to Session requests.
I want to fire Session_Start Event in Application's Global.asax. according to the Microsoft's .NET 4.5 framework SessionStateModule Source
Code i invoke Session Start event handler (hooked by asp.net) in Asynchronous httpApplication's app_BeginAcquireState event in my Custom Session Module as follows:
public void Init(HttpApplication app)
// Handling OnAcquireRequestState Asynchronously
private IAsyncResult app_BeginAcquireState(object source, EventArgs e, AsyncCallback cb, object extraData)
// Firing Sessoin_Start Event
but the problem is that the Session Object in Session_Start is not constructed and available yet and does not exist! and no key/value can be added to the Session at this time and i it throws Exception.
this useful post as a solution to mark HttpContext's Handler as IRequiresSessionState and
IReadOnlySessionState in Application_PostMapRequestHandler. i handled Start Invoking in
AcquireState that is before PostAcquireRequestState also i added async event for BeginAcquireState to handle Concurrency on Session Request. so when i mark the HttpContext's Handler to IRequireSessionState in BeginAcquireState still Session
is not available in MyModule_Start (Session_Start) event handler!
Where should i handle this solution to have Session object to invoke Session Start event? or in which event should i handle my BeginAcquireState work that initializes new Sessions in SessionStoreProvider.
notice that i have removed default session module and added MyCustomSessionStateModule:
<add name="MyCustomSessionStateModule" type="CustomSessionStateServer.MyCustomSessionStateModule" />