public void Init (HttpApplication app)
{
config = (SessionStateSection) WebConfigurationManager.GetSection ("system.web/sessionState");
ProviderSettings settings;
switch (config.Mode) {
case SessionStateMode.Custom:
settings = config.Providers [config.CustomProvider];
if (settings == null)
throw new HttpException (String.Format ("Cannot find '{0}' provider.", config.CustomProvider));
break;
case SessionStateMode.Off:
return;
case SessionStateMode.InProc:
settings = new ProviderSettings (null, typeof (SessionInProcHandler).AssemblyQualifiedName);
break;
case SessionStateMode.SQLServer:
settings = new ProviderSettings (null, typeof (SessionSQLServerHandler).AssemblyQualifiedName);
break;
case SessionStateMode.StateServer:
settings = new ProviderSettings (null, typeof (SessionStateServerHandler).AssemblyQualifiedName);
break;
default:
throw new NotImplementedException (String.Format ("The mode '{0}' is not implemented.", config.Mode));
}
handler = (SessionStateStoreProviderBase) ProvidersHelper.InstantiateProvider (settings, typeof (SessionStateStoreProviderBase));
if (String.IsNullOrEmpty(config.SessionIDManagerType)) {
idManager = new SessionIDManager ();
} else {
Type idManagerType = HttpApplication.LoadType (config.SessionIDManagerType, true);
idManager = (ISessionIDManager)Activator.CreateInstance (idManagerType);
}
try {
idManager.Initialize ();
} catch (Exception ex) {
throw new HttpException ("Failed to initialize session ID manager.", ex);
}
supportsExpiration = handler.SetItemExpireCallback (OnSessionExpired);
HttpRuntimeSection runtime = HttpRuntime.Section;
executionTimeout = runtime.ExecutionTimeout;
//executionTimeoutMS = executionTimeout.Milliseconds;
this.app = app;
app.BeginRequest += new EventHandler (OnBeginRequest);
app.AcquireRequestState += new EventHandler (OnAcquireRequestState);
app.ReleaseRequestState += new EventHandler (OnReleaseRequestState);
app.EndRequest += new EventHandler (OnEndRequest);
}