public void Init(HttpApplication app)
        {
            if (!initialized)
            {
                lock (typeof(RedisSessionStateModule)) {
                    if (!initialized)
                    {
                        redisConfig = RedisSessionStateConfiguration.GetConfiguration();

                        // Add event handlers.
                        app.AcquireRequestState += new EventHandler(this.OnAcquireRequestState);
                        app.ReleaseRequestState += new EventHandler(this.OnReleaseRequestState);
                        app.EndRequest          += new EventHandler(this.OnEndRequest);

                        // Create a SessionIDManager.
                        sessionIDManager = new SessionIDManager();
                        sessionIDManager.Initialize();

                        redisConnection = new RedisConnection(redisConfig.Host, redisConfig.Port);

                        initialized = true;
                    }
                }
            }
        }
        /// <summary>
        /// IHttpModule.Init
        /// </summary>
        /// <param name="app"></param>
        public void Init(HttpApplication app)
        {
            // Add event handlers.
            app.AcquireRequestState += OnAcquireRequestState;
            app.ReleaseRequestState += OnReleaseRequestState;
            app.EndRequest          += OnEndRequest;

            // Create a SessionIDManager.
            sessionIdManager = new SessionIDManager();
            sessionIdManager.Initialize();

            // If not already initialized, initialize timer and configuration.
            if (!initialized)
            {
                lock (LockObject)
                {
                    if (!initialized)
                    {
                        OnInit();

                        // Get the configuration section and set timeout and CookieMode values.
                        Configuration cfg =
                            WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
                        SessionStateSection config = (SessionStateSection)cfg.GetSection("system.web/sessionState");

                        Timeout    = (int)config.Timeout.TotalMinutes;
                        CookieMode = config.Cookieless;

                        initialized = true;
                    }
                }
            }
        }
        //
        // IHttpModule.Init
        //
        public void Init(HttpApplication app)
        {
            // Add event handlers.
            app.AcquireRequestState += new EventHandler(this.OnAcquireRequestState);
            app.ReleaseRequestState += new EventHandler(this.OnReleaseRequestState);
            app.EndRequest          += new EventHandler(this.OnEndRequest);

            // Create a SessionIDManager.
            pSessionIDManager = new SessionIDManager();
            pSessionIDManager.Initialize();

            // If not already initialized, initialize timer and configuration.
            if (!pInitialized)
            {
                lock (typeof(LockFreeSessionStateModule))
                {
                    if (!pInitialized)
                    {
                        // Create a Timer to invoke the ExpireCallback method based on
                        // the pTimerSeconds value (e.g. every 10 seconds).

                        pTimer = new Timer(new TimerCallback(this.ExpireCallback),
                                           null,
                                           0,
                                           pTimerSeconds * 1000);

                        // Get the configuration section and set timeout and CookieMode values.
                        Configuration cfg =
                            WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
                        pConfig = (SessionStateSection)cfg.GetSection("system.web/sessionState");

                        pTimeout    = (int)pConfig.Timeout.TotalMinutes;
                        pCookieMode = pConfig.Cookieless;

                        pInitialized = true;
                    }
                }
            }
        }
        public void Init(HttpApplication app)
        {
            if (!initialized) {
                lock (typeof(RedisSessionStateModule)) {
                    if (!initialized) {

                        redisConfig = RedisSessionStateConfiguration.GetConfiguration();

                        // Add event handlers.
                        app.AcquireRequestState += new EventHandler(this.OnAcquireRequestState);
                        app.ReleaseRequestState += new EventHandler(this.OnReleaseRequestState);
                        app.EndRequest += new EventHandler(this.OnEndRequest);

                        // Create a SessionIDManager.
                        sessionIDManager = new SessionIDManager();
                        sessionIDManager.Initialize();

                        redisConnection = new RedisConnection(redisConfig.Host, redisConfig.Port);

                        initialized = true;
                    }
                }
            }
        }
Esempio n. 5
0
        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);
        }