private ValidationResult ValidateInternal(string id)
        {
            if (String.IsNullOrEmpty(id))
            {
                return(new ValidationResult()
                {
                    IsValid = false
                });
            }

            var ids = GetSessionIdAndServer(id);

            if (ids.Length != 3)
            {
                return(new ValidationResult()
                {
                    IsValid = false
                });
            }

            var serverId  = ids[1];
            var sessionId = ids[0];
            var timestamp = GetSessionTimestamp(id);

            //If the session id is well-formed, use a shared session server to validate it
            var result = SharedSessionServerManager.IsValid(serverId, sessionId, timestamp);

            return(result);
        }
        /// <summary>
        /// Creates a valid Session ID. If there is a cookie present from this - or another -  shared-session
        /// application try to reuse the existing Session ID
        /// </summary>
        /// <param name="context">The HttpContext of the current request</param>
        /// <returns>A valid Session ID</returns>
        public string CreateSessionID(HttpContext context)
        {
            string id = String.Empty;

            // If there is a Shared Session cookie and it is valid, return
            // the stored ID
            if (HasSharedSessionCookie(context.Request.Cookies))
            {
                id = GetCookieValue(context);
                if (Validate(id))
                {
                    return(id);
                }
            }

            // If no valid ID was found, generate a new one, asociating the session
            // with an avaliable Shared Session server
            Guid   guid     = Guid.NewGuid();
            string serverId = SharedSessionServerManager.GetNextServerId();

            DateTime timestamp = DateTime.Now;

            SharedSessionServerManager.SetData(serverId, guid.ToString(), String.Empty, timestamp);

            id = GetFullSessionID(serverId, guid.ToString(), timestamp);

            return(id);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Resets a session timeout
 /// </summary>
 /// <param name="context">The current request context</param>
 /// <param name="id">The session id</param>
 public override void ResetItemTimeout(HttpContext context, string id)
 {
     // Force a session get to update its timeout
     var ids       = SharedSessionIDManager.GetSessionIdAndServer(id);
     var timestamp = SharedSessionIDManager.GetSessionTimestamp(id);
     var data      = SharedSessionServerManager.GetData(ids[1], ids[0], timestamp);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Removes an item from the session store
        /// </summary>
        /// <param name="context">The current request context</param>
        /// <param name="id">The session id</param>
        /// <param name="lockId">The lock id</param>
        /// <param name="item">The item to remove</param>
        public override void RemoveItem(
            HttpContext context,
            string id,
            object lockId,
            SessionStateStoreData item)
        {
            var ids = SharedSessionIDManager.GetSessionIdAndServer(id);

            SharedSessionServerManager.Remove(ids[1], ids[0]);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Adds a new session-state item to the data store.
        /// </summary>
        /// <param name="context">The current request context</param>
        /// <param name="id">The System.Web.SessionState.HttpSessionState.SessionID for the current request.</param>
        /// <param name="timeout">The timeout for the current request</param>
        public override void CreateUninitializedItem(HttpContext context, string id, int timeout)
        {
            var ids = SharedSessionIDManager.GetSessionIdAndServer(id);

            if (ids == null || ids.Length != 3)
            {
                throw new ArgumentException("Invalid ID", "id");
            }
            var timestamp = SharedSessionIDManager.GetSessionTimestamp(id);

            SharedSessionServerManager.SetData(ids[1], ids[0], string.Empty, timestamp);
        }
Ejemplo n.º 6
0
        /// <summary>Updates the session-item information in the session-state data store
        /// with values from the current request, and clears the lock on the data.
        /// </summary>
        /// <param name="context">The current request context</param>
        /// <param name="id">The session id</param>
        /// <param name="item">The data to store</param>
        /// <param name="lockId">The lock id</param>
        /// <param name="newItem">Indicates if it is a new item</param>
        public override void SetAndReleaseItemExclusive(
            HttpContext context,
            string id,
            SessionStateStoreData item,
            object lockId,
            bool newItem)
        {
            //Stores the data in a shared session server
            var ids       = SharedSessionIDManager.GetSessionIdAndServer(id);
            var timestamp = DateTime.Now;             // new timestamp

            SharedSessionServerManager.SetData(ids[1], ids[0], Serialize((SessionStateItemCollection)item.Items), timestamp);

            // Update the session id information with the new timestamp
            SharedSessionIDManager.UpdateCurrentSessionIdTimestamp(context, id, timestamp);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Returns read-only session-state data from the session data store.
        /// </summary>
        /// <param name="context">The current request context</param>
        /// <param name="id">The session id</param>
        /// <param name="locked">Indicates if the item is locked in the data store (always false)</param>
        /// <param name="lockAge">Indicates the age of the lock (always TimeSpan.MaxValue)</param>
        /// <param name="lockId">An object that represents the lock ID</param>
        /// <param name="actions">Actions to perform after the request (always SessionStateActions.None)</param>
        /// <returns></returns>
        public override SessionStateStoreData GetItem(
            HttpContext context,
            string id,
            out bool locked,
            out TimeSpan lockAge,
            out object lockId,
            out SessionStateActions actions)
        {
            var ids       = SharedSessionIDManager.GetSessionIdAndServer(id);
            var timestamp = SharedSessionIDManager.GetSessionTimestamp(id);
            var data      = SharedSessionServerManager.GetData(ids[1], ids[0], timestamp);

            locked  = false;
            lockAge = TimeSpan.MaxValue;
            lockId  = new Object();
            actions = SessionStateActions.None;

            return(Deserialize(context, data.Data, data.TimeOut));
        }