コード例 #1
0
    /// <summary>
    /// Updates a locked session and releases the lock.
    /// </summary>
    /// <param name="context">The current request's HttpContext.</param>
    /// <param name="id">The session id for the current request.</param>
    /// <param name="item">The SessionStateStoreData object that contains the current session values to be stored.</param>
    /// <param name="lockId">The lock id for the current request.</param>
    /// <param name="newItem">Whether this is a new item or not.</param>
    public override void SetAndReleaseItemExclusive(HttpContext context, String id, SessionStateStoreData item, object lockId, bool newItem)
    {
        // Set session
        client.Set(GetSessionHash(id), Serialize((SessionStateItemCollection)item.Items), sessionConfig.Timeout);

        // Remove lock (no longer exclusive)
        client.Delete(GetSessionLockHash(id));
    }
 public abstract virtual void SetAndReleaseItemExclusive(System.Web.HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem)
 {
 }
コード例 #3
0
    /// <summary>
    /// Deletes a session.
    /// </summary>
    /// <param name="context">The current request's HttpContext.</param>
    /// <param name="id">The session id for the current request.</param>
    /// <param name="lockId">The lock id for the current request.</param>
    /// <param name="item">The SessionStateStoreData to be removed.</param>
    /// <remarks>The SessionStateStoreData is not used in this case since we use the session id to generate the Memcached key.</remarks>
    public override void RemoveItem(HttpContext context, String id, object lockId, SessionStateStoreData item)
    {
        client.Delete(GetSessionHash(id));

        // Notice we're not removing the lock here even though
        // we should, but since session ids are unique there's no reason
        // to waste time waiting for the delete to finish.

        // If you want to delete the lock object anyway uncomment the line below
        //client.Delete(GetSessionLockHash(id));
    }
 public abstract virtual void RemoveItem(System.Web.HttpContext context, string id, object lockId, SessionStateStoreData item)
 {
 }
コード例 #5
0
        /// <summary>
        /// This method updates the session time information in the database with the specified session item,
        /// and releases the lock.
        /// </summary>
        /// <param name="context">The HttpContext object for the current request</param>
        /// <param name="id">The session ID for the current request</param>
        /// <param name="item">The session item containing new values to update the session item in the database with.
        /// </param>
        /// <param name="lockId">The lock identifier for the current request.</param>
        /// <param name="newItem">A Boolean value that indicates whether or not the session item is new in the database.
        /// A false value indicates an existing item.
        /// </param>
        public override void SetAndReleaseItemExclusive(System.Web.HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem)
        {
            try {
                using (MySqlConnection conn = new MySqlConnection(connectionString)) {
                    // Serialize the SessionStateItemCollection as a byte array
                    byte[] sessItems = Serialize((SessionStateItemCollection)item.Items);
                    MySqlCommand cmd;
                    if (newItem) {
                        //Insert the new session item . If there was expired session
                        //with the same SessionId and Application id, it will be removed

                        cmd = new MySqlCommand(
                            "REPLACE INTO my_aspnet_sessions (SessionId, ApplicationId, Created, Expires," +
                " LockDate, LockId, Timeout, Locked, SessionItems, Flags)" +
                " Values(@SessionId, @ApplicationId, NOW(), NOW() + INTERVAL @Timeout MINUTE, NOW()," +
                " @LockId , @Timeout, @Locked, @SessionItems, @Flags)", conn);
                        cmd.Parameters.AddWithValue("@SessionId", id);
                        cmd.Parameters.AddWithValue("@ApplicationId", ApplicationKey);
                        cmd.Parameters.AddWithValue("@Timeout", item.Timeout);
                        cmd.Parameters.AddWithValue("@LockId", 0);
                        cmd.Parameters.AddWithValue("@Locked", 0);
                        cmd.Parameters.AddWithValue("@SessionItems", sessItems);
                        cmd.Parameters.AddWithValue("@Flags", 0);
                    } else {
                        //Update the existing session item.
                        cmd = new MySqlCommand(
                             "UPDATE my_aspnet_sessions SET Expires = NOW() + INTERVAL @Timeout MINUTE," +
                 " SessionItems = @SessionItems, Locked = @Locked " +
                 " WHERE SessionId = @SessionId AND ApplicationId = @ApplicationId AND LockId = @LockId",
                             conn);

                        cmd.Parameters.AddWithValue("@Timeout", item.Timeout);
                        cmd.Parameters.AddWithValue("@SessionItems", sessItems);
                        cmd.Parameters.AddWithValue("@Locked", 0);
                        cmd.Parameters.AddWithValue("@SessionId", id);
                        cmd.Parameters.AddWithValue("@ApplicationId", ApplicationKey);
                        cmd.Parameters.AddWithValue("@LockId", lockId);
                    }

                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
            } catch (MySqlException e) {
                HandleMySqlException(e, "SetAndReleaseItemExclusive");
            }
        }
コード例 #6
0
        /// <summary>
        /// This method removes the specified session item from the database
        /// </summary>
        /// <param name="context">The HttpContext object for the current request</param>
        /// <param name="id">The session ID for the current request</param>
        /// <param name="lockId">The lock identifier for the current request.</param>
        /// <param name="item">The session item to remove from the database.</param>
        public override void RemoveItem(System.Web.HttpContext context, string id, object lockId, SessionStateStoreData item)
        {
            try {
                using (MySqlConnection conn = new MySqlConnection(connectionString)) {
                    MySqlCommand cmd = new MySqlCommand("DELETE FROM my_aspnet_sessions " +
              " WHERE SessionId = @SessionId AND ApplicationId = @ApplicationId AND LockId = @LockId",
                        conn);

                    cmd.Parameters.AddWithValue("@SessionId", id);
                    cmd.Parameters.AddWithValue("@ApplicationId", ApplicationKey);
                    cmd.Parameters.AddWithValue("@LockId", lockId);

                    conn.Open();
                    cmd.ExecuteNonQuery();
                }

            } catch (MySqlException e) {
                HandleMySqlException(e, "RemoveItem");
            }
        }
コード例 #7
0
    } // End of the Deserialize method

    #endregion

    #region Delete methods

    /// <summary>
    /// Remove a session item
    /// </summary>
    public override void RemoveItem(HttpContext context, string id, object lockId, SessionStateStoreData item)
    {
        // Delete the session post
        WebshopSession.DeleteOnId(id, this.applicationName, (int)lockId);
        
    } // End of the RemoveItem method
コード例 #8
0
    } // End of the SetItemExpireCallback method

    /// <summary>
    /// Set and realease a session post
    /// </summary>
    public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem)
    {
        // Serialize the SessionStateItemCollection as a string.
        string sessItems = Serialize((SessionStateItemCollection)item.Items);

        // Create a webshop session
        WebshopSession webshopSession = new WebshopSession();
        webshopSession.id = id;
        webshopSession.application_name = this.applicationName;
        webshopSession.created_date = DateTime.UtcNow;
        webshopSession.expires_date = DateTime.UtcNow.AddMinutes((Double)item.Timeout);
        webshopSession.lock_date = DateTime.UtcNow;
        webshopSession.lock_id = 0;
        webshopSession.timeout_limit = item.Timeout;
        webshopSession.locked = false;
        webshopSession.session_items = sessItems;
        webshopSession.flags = 0;

        if (newItem == true)
        {
            // Delete the session if it exists
            WebshopSession.DeleteOnId(id, this.applicationName);

            // Add the session
            WebshopSession.Add(webshopSession);

        }
        else
        {
            // Update session values
            webshopSession.lock_id = (Int32)lockId;

            // Update the session
            WebshopSession.UpdateWithLockId(webshopSession);
        }

    } // End of the SetAndReleaseItemExclusive method