Ejemplo n.º 1
0
        private void OnAcquireRequestState(object source, EventArgs args)
        {
            HttpApplication app     = (HttpApplication)source;
            HttpContext     context = app.Context;
            bool            isNew   = false;
            string          sessionId;

            RedisSessionItemHash sessionItemCollection = null;
            bool supportSessionIDReissue = true;

            sessionIDManager.InitializeRequest(context, false, out supportSessionIDReissue);
            sessionId = sessionIDManager.GetSessionID(context);

            if (sessionId == null)
            {
                bool redirected, cookieAdded;

                sessionId = sessionIDManager.CreateSessionID(context);
                sessionIDManager.SaveSessionID(context, sessionId, out redirected, out cookieAdded);

                isNew = true;

                if (redirected)
                {
                    return;
                }
            }

            if (!RequiresSessionState(new HttpContextWrapper(context)))
            {
                return;
            }

            releaseCalled = false;

            sessionItemCollection = new RedisSessionItemHash(sessionId, redisConfig.SessionTimeout, GetRedisConnection());

            if (sessionItemCollection.Count == 0)
            {
                isNew = true;
            }

            // Add the session data to the current HttpContext.
            SessionStateUtility.AddHttpSessionStateToContext(context,
                                                             new TaskWaitRedisHttpSessionStateContainer(sessionId,
                                                                                                        sessionItemCollection,
                                                                                                        SessionStateUtility.GetSessionStaticObjects(context),
                                                                                                        redisConfig.SessionTimeout,
                                                                                                        isNew,
                                                                                                        redisConfig.CookieMode,
                                                                                                        SessionStateMode.Custom,
                                                                                                        false));

            // Execute the Session_OnStart event for a new session.
            if (isNew && Start != null)
            {
                Start(this, EventArgs.Empty);
            }
        }
        public TaskWaitRedisHttpSessionStateContainer(string id,
													RedisSessionItemHash sessionItems,
													HttpStaticObjectsCollection staticObjects,
													int timeout,
													bool newSession,
													HttpCookieMode cookieMode,
													SessionStateMode mode,
													bool isReadonly)
            : base(id, sessionItems, staticObjects, timeout, newSession, cookieMode, mode, isReadonly)
        {
            SessionItems = sessionItems;
        }
Ejemplo n.º 3
0
 public TaskWaitRedisHttpSessionStateContainer(string id,
                                               RedisSessionItemHash sessionItems,
                                               HttpStaticObjectsCollection staticObjects,
                                               int timeout,
                                               bool newSession,
                                               HttpCookieMode cookieMode,
                                               SessionStateMode mode,
                                               bool isReadonly)
     : base(id, sessionItems, staticObjects, timeout, newSession, cookieMode, mode, isReadonly)
 {
     SessionItems = sessionItems;
 }
        private void OnAcquireRequestState(object source, EventArgs args)
        {
            HttpContext context    = ((HttpApplication)source).Context;
            bool        newSession = false;
            bool        supportSessionIDReissue = true;

            this.sessionIDManager.InitializeRequest(context, false, out supportSessionIDReissue);
            string sessionId = this.sessionIDManager.GetSessionID(context);

            if (sessionId == null)
            {
                sessionId = this.sessionIDManager.CreateSessionID(context);
                bool redirected;
                bool cookieAdded;
                this.sessionIDManager.SaveSessionID(context, sessionId, out redirected, out cookieAdded);
                newSession = true;
                if (redirected)
                {
                    return;
                }
            }
            if (!this.RequiresSessionState((HttpContextBase) new HttpContextWrapper(context)))
            {
                return;
            }
            this.releaseCalled = false;
            RedisSessionItemHash sessionItems = new RedisSessionItemHash(sessionId, this.redisConfig.SessionTimeout, this.GetRedisConnection());

            if (sessionItems.Count == 0)
            {
                newSession = true;
            }
            SessionStateUtility.AddHttpSessionStateToContext(context, (IHttpSessionState) new TaskWaitRedisHttpSessionStateContainer(sessionId, sessionItems, SessionStateUtility.GetSessionStaticObjects(context), this.redisConfig.SessionTimeout, newSession, this.redisConfig.CookieMode, SessionStateMode.Custom, false));
            if (!newSession || this.Start == null)
            {
                return;
            }
            this.Start((object)this, EventArgs.Empty);
        }
Ejemplo n.º 5
0
        private void OnAcquireRequestState(object source, EventArgs args)
        {
            HttpApplication app = (HttpApplication)source;
            HttpContext context = app.Context;
            bool isNew = false;
            string sessionId;

            RedisSessionItemHash sessionItemCollection = null;
            bool supportSessionIDReissue = true;

            sessionIDManager.InitializeRequest(context, false, out supportSessionIDReissue);
            sessionId = sessionIDManager.GetSessionID(context);

            if (sessionId == null) {
                bool redirected, cookieAdded;

                sessionId = sessionIDManager.CreateSessionID(context);
                sessionIDManager.SaveSessionID(context, sessionId, out redirected, out cookieAdded);

                isNew = true;

                if (redirected)
                    return;
            }

            if (!RequiresSessionState(new HttpContextWrapper(context))) { return; }

            releaseCalled = false;

            sessionItemCollection = new RedisSessionItemHash(sessionId, redisConfig.SessionTimeout, GetRedisConnection(), redisConfig.SessionSerializer);
            sessionItemCollection.DeserializationError += (sender, e) => redisConfig.RaiseDeserializationError(this, e);

            if (sessionItemCollection.Count == 0) {
                isNew = true;
            }

            // Add the session data to the current HttpContext.
            SessionStateUtility.AddHttpSessionStateToContext(context,
                                  new TaskWaitRedisHttpSessionStateContainer(sessionId,
                                                                         sessionItemCollection,
                                                                         SessionStateUtility.GetSessionStaticObjects(context),
                                                                         redisConfig.SessionTimeout,
                                                                         isNew,
                                                                         redisConfig.CookieMode,
                                                                         SessionStateMode.Custom,
                                                                         false));

            // Execute the Session_OnStart event for a new session.
            if (isNew && Start != null) {
                Start(this, EventArgs.Empty);
            }
        }