This class allows ASP.NET applications to store and manage session state information in a MySQL database. Expired session data is periodically deleted from the database.
Наследование: System.Web.SessionState.SessionStateStoreProviderBase
Пример #1
0
        public void DeleteSessionAppSpecific()
        {
            // create two sessions of different appId
              // it should delete only 1
              CreateSessionData(1, DateTime.Now.Subtract(new TimeSpan(1, 0, 0)));
              CreateSessionData(2, DateTime.Now.Subtract(new TimeSpan(1, 0, 0)));

              MySqlSessionStateStore session = new MySqlSessionStateStore();

              NameValueCollection config = new NameValueCollection();
              config.Add("connectionStringName", "LocalMySqlServer");
              config.Add("applicationName", "/");
              config.Add("enableExpireCallback", "false" );
              session.Initialize("SessionTests", config);

              session.Dispose();

              int i = 0;
              while (((long)MySqlHelper.ExecuteScalar(conn, "SELECT Count(*) FROM my_aspnet_sessions;") != 0) && (i < 10))
              {
            Thread.Sleep(500);
            i++;
              }

              Assert.AreEqual(1, CountSessions());
        }
Пример #2
0
        private void SetSessionItemExpiredCallback(bool includeCallback)
        {
            _evt = new AutoResetEvent(false);
              calledId = null;

              CreateSessionData(1, DateTime.Now.Subtract(new TimeSpan(1, 0, 0)));

              MySqlSessionStateStore session = new MySqlSessionStateStore();

              NameValueCollection config = new NameValueCollection();
              config.Add("connectionStringName", "LocalMySqlServer");
              config.Add("applicationName", "/");
              config.Add("enableExpireCallback", includeCallback ? "true" : "false");
              session.Initialize("SessionProvTest", config);
              if (includeCallback) session.SetItemExpireCallback(expireCallback);
              Thread.Sleep(1000);
              session.Dispose();
        }