/// <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);
        }
Пример #2
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);
        }
Пример #3
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);
        }