private void InitModuleFromConfig(HttpApplication app, SessionStateSection config)
        {
            if (config.Mode != SessionStateMode.Off)
            {
                app.AddOnAcquireRequestStateAsync(new BeginEventHandler(this.BeginAcquireState), new EndEventHandler(this.EndAcquireState));
                app.ReleaseRequestState += new EventHandler(this.OnReleaseState);
                app.EndRequest          += new EventHandler(this.OnEndRequest);
                this._partitionResolver  = this.InitPartitionResolver(config);
                switch (config.Mode)
                {
                case SessionStateMode.InProc:
                    if (HttpRuntime.UseIntegratedPipeline)
                    {
                        s_canSkipEndRequestCall = true;
                    }
                    this._store = new InProcSessionStateStore();
                    this._store.Initialize(null, null);
                    break;

                case SessionStateMode.StateServer:
                    if (HttpRuntime.UseIntegratedPipeline)
                    {
                        s_canSkipEndRequestCall = true;
                    }
                    this._store = new OutOfProcSessionStateStore();
                    ((OutOfProcSessionStateStore)this._store).Initialize(null, null, this._partitionResolver);
                    break;

                case SessionStateMode.SQLServer:
                    this._store = new SqlSessionStateStore();
                    ((SqlSessionStateStore)this._store).Initialize(null, null, this._partitionResolver);
                    break;

                case SessionStateMode.Custom:
                    this._store = this.InitCustomStore(config);
                    break;
                }
                this._idManager = this.InitSessionIDManager(config);
                if (((config.Mode == SessionStateMode.InProc) || (config.Mode == SessionStateMode.StateServer)) && this._usingAspnetSessionIdManager)
                {
                    this._ignoreImpersonation = true;
                }
            }
        }
Пример #2
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);
        }
Пример #3
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);
		}
        /// <summary>
        /// Checks the provider.
        /// </summary>
        private static void CheckProvider(SessionStateStoreProviderBase provider)
        {
            bool locked;
            TimeSpan lockAge;
            object lockId;
            SessionStateActions actions;

            provider.InitializeRequest(HttpContext);
            provider.CreateUninitializedItem(HttpContext, Id, 42);

            var data = provider.GetItem(HttpContext, Id, out locked, out lockAge, out lockId, out actions);
            Assert.IsNotNull(data);
            Assert.AreEqual(42, data.Timeout);
            Assert.IsFalse(locked);
            Assert.AreEqual(TimeSpan.Zero, lockAge);
            Assert.IsNull(lockId);
            Assert.AreEqual(SessionStateActions.None, actions);

            provider.ResetItemTimeout(HttpContext, Id);
            provider.EndRequest(HttpContext);
            provider.Dispose();
        }
Пример #5
0
        void InitModuleFromConfig(HttpApplication app, SessionStateSection config) {
            if (config.Mode == SessionStateMode.Off) {
                return;
            }

            app.AddOnAcquireRequestStateAsync(
                    new BeginEventHandler(this.BeginAcquireState),
                    new EndEventHandler(this.EndAcquireState));

            app.ReleaseRequestState += new EventHandler(this.OnReleaseState);
            app.EndRequest += new EventHandler(this.OnEndRequest);

            _partitionResolver = InitPartitionResolver(config);

            switch (config.Mode) {
                case SessionStateMode.InProc:
                    if (HttpRuntime.UseIntegratedPipeline) {
                        s_canSkipEndRequestCall = true;
                    }
                    _store = new InProcSessionStateStore();
                    _store.Initialize(null, null);
                    break;

#if !FEATURE_PAL // FEATURE_PAL does not enable out of proc session state
                case SessionStateMode.StateServer:
                    if (HttpRuntime.UseIntegratedPipeline) {
                        s_canSkipEndRequestCall = true;
                    }
                    _store = new OutOfProcSessionStateStore();
                    ((OutOfProcSessionStateStore)_store).Initialize(null, null, _partitionResolver);
                    break;

                case SessionStateMode.SQLServer:
                    _store = new SqlSessionStateStore();
                    ((SqlSessionStateStore)_store).Initialize(null, null, _partitionResolver);
#if DBG
                    ((SqlSessionStateStore)_store).SetModule(this);
#endif
                    break;
#else // !FEATURE_PAL
                case SessionStateMode.StateServer:
                    throw new NotImplementedException("ROTORTODO");
                    break;

                case SessionStateMode.SQLServer:
                    throw new NotImplementedException("ROTORTODO");
                    break;
#endif // !FEATURE_PAL

                case SessionStateMode.Custom:
                    _store = InitCustomStore(config);
                    break;

                default:
                    break;
            }

            // We depend on SessionIDManager to manage session id
            _idManager = InitSessionIDManager(config);

            if ((config.Mode == SessionStateMode.InProc || config.Mode == SessionStateMode.StateServer) &&
                _usingAspnetSessionIdManager) {
                // If we're using InProc mode or StateServer mode, and also using our own session id module,
                // we know we don't care about impersonation in our all session state store read/write
                // and session id read/write.
                _ignoreImpersonation = true;
            }

        }
        private void InitModuleFromConfig(HttpApplication app, SessionStateSection config)
        {
            if (config.Mode != SessionStateMode.Off)
            {
                app.AddOnAcquireRequestStateAsync(new BeginEventHandler(this.BeginAcquireState), new EndEventHandler(this.EndAcquireState));
                app.ReleaseRequestState += new EventHandler(this.OnReleaseState);
                app.EndRequest += new EventHandler(this.OnEndRequest);
                this._partitionResolver = this.InitPartitionResolver(config);
                switch (config.Mode)
                {
                    case SessionStateMode.InProc:
                        if (HttpRuntime.UseIntegratedPipeline)
                        {
                            s_canSkipEndRequestCall = true;
                        }
                        this._store = new InProcSessionStateStore();
                        this._store.Initialize(null, null);
                        break;

                    case SessionStateMode.StateServer:
                        if (HttpRuntime.UseIntegratedPipeline)
                        {
                            s_canSkipEndRequestCall = true;
                        }
                        this._store = new OutOfProcSessionStateStore();
                        ((OutOfProcSessionStateStore) this._store).Initialize(null, null, this._partitionResolver);
                        break;

                    case SessionStateMode.SQLServer:
                        this._store = new SqlSessionStateStore();
                        ((SqlSessionStateStore) this._store).Initialize(null, null, this._partitionResolver);
                        break;

                    case SessionStateMode.Custom:
                        this._store = this.InitCustomStore(config);
                        break;
                }
                this._idManager = this.InitSessionIDManager(config);
                if (((config.Mode == SessionStateMode.InProc) || (config.Mode == SessionStateMode.StateServer)) && this._usingAspnetSessionIdManager)
                {
                    this._ignoreImpersonation = true;
                }
            }
        }
        /// <summary>
        /// Checks item expiration.
        /// </summary>
        private static void CheckExpiry(SessionStateStoreProviderBase provider)
        {
            bool locked;
            TimeSpan lockAge;
            object lockId;
            SessionStateActions actions;

            // Check that item is present.
            var res = provider.GetItem(HttpContext, Id, out locked, out lockAge, out lockId, out actions);
            Assert.IsNotNull(res);

            // Wait a minute and check again.
            Thread.Sleep(TimeSpan.FromMinutes(1.05));

            res = provider.GetItem(HttpContext, Id, out locked, out lockAge, out lockId, out actions);
            Assert.IsNull(res);
        }