Пример #1
0
 /// <summary>
 /// This method is fired when an item is removed from the cache.  It is used to detect when a cache item
 /// expires, indicating that the session has expired, and fires the SessionEnd event.
 /// </summary>
 private void CacheItemRemovedCallbackMethod(string key, object value, CacheItemRemovedReason reason)
 {
     if (reason == CacheItemRemovedReason.Expired)
     {
         if (SessionEnd != null)
         {
             SessionEndedEventArgs e = new SessionEndedEventArgs(key, value);
             SessionEnd(this, e);
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Fires the session end event and removes it from the
        /// application cache (so it doesnt fire again)
        /// </summary>
        public static void EndSession()
        {
            // Ensure we have a session key
            if (SessionObjectKey == null)
            {
                return;
            }

            // Ensure we have a HttpContext
            if (HttpContext.Current == null)
            {
                Debug.WriteLine("No current http context");
                return;
            }

            // Get the current session
            HttpSessionState currentSession = HttpContext.Current.Session;

            // Ensure we have a current session
            if (currentSession == null)
            {
                Debug.WriteLine("No current session");
                return;
            }

            if (SessionEnd != null)
            {
                string key   = currentSession.SessionID;
                object value = currentSession[SessionObjectKey];

                SessionEndedEventArgs e = new SessionEndedEventArgs(key, value);
                SessionEnd(null, e);
            }

            // Remove the session from the cache
            HttpContext.Current.Cache.Remove(currentSession.SessionID);
        }