Exemple #1
0
 private void LogException(HttpContextBase context, Exception ex)
 {
     if (RedisSessionConfig.RedisSessionAccessorExceptionLoggingDel != null)
     {
         RedisSessionConfig.RedisSessionAccessorExceptionLoggingDel(context, "RedisSessionAccessor unable to get Redis session for id: " + this.SessionRedisHashKey, ex);
     }
 }
        /// <summary>
        /// Initializes a new instance of the RedisSessionAccessor class, which provides access to a
        ///     local Redis items collection outside of the standard ASP.NET pipeline Session hooks
        /// </summary>
        /// <param name="context">The context of the current request</param>
        public RedisSessionAccessor(HttpContextBase context)
        {
            try
            {
                this.RequestContext = context;
                this.SharedSessions = new LocalSharedSessionDictionary();

                // if we have the session ID
                if (this.RequestContext.Request.Cookies[RedisSessionConfig.SessionHttpCookieName] != null)
                {
                    this.SessionRedisHashKey = RedisSessionStateStoreProvider.RedisHashIdFromSessionId(
                        this.RequestContext,
                        this.RequestContext.Request.Cookies[RedisSessionConfig.SessionHttpCookieName].Value);
                }

                if (!string.IsNullOrEmpty(this.SessionRedisHashKey))
                {
                    RedisSessionStateItemCollection items =
                        this.SharedSessions.GetSessionForBeginRequest(
                            this.SessionRedisHashKey,
                            (string redisKey) =>
                    {
                        return(RedisSessionStateStoreProvider.GetItemFromRedis(
                                   redisKey,
                                   this.RequestContext,
                                   RedisSessionConfig.SessionTimeout));
                    });

                    this.Session = new FakeHttpSessionState(
                        items,
                        this.RequestContext.Request.Cookies[RedisSessionConfig.SessionHttpCookieName].Value);
                }
            }
            catch (Exception exc)
            {
                if (RedisSessionConfig.RedisSessionAccessorExceptionLoggingDel != null)
                {
                    string errMsg = string.Format(
                        "RedisSessionAccessor unable to get Redis session for id: {0}",
                        this.SessionRedisHashKey);

                    RedisSessionConfig.RedisSessionAccessorExceptionLoggingDel(
                        context,
                        errMsg,
                        exc);
                }
            }
        }