/// <summary> /// Create a new instance of the user session controller /// </summary> /// <returns>The new instance else null.</returns> public static UserOnlineController CreateInstance() { // Get the current user identity name. UserOnlineController userOnlineController = null; string userIdentityName = HttpContext.Current.User.Identity.Name; // If the identity is null then the // user is anonymous if (String.IsNullOrEmpty(userIdentityName)) { // Get the anonymous id assigned userIdentityName = HttpContext.Current.Request.AnonymousID; // If no anonymous id has been assigned // the throw exception. if (String.IsNullOrEmpty(userIdentityName)) { throw new Exception("The current http context user identity is anonymous, unable to crate a online user controller."); } else { // Assign the new controller with the anonymous id. userOnlineController = new UserOnlineController(true, userIdentityName, null); } } else { // Assign the new controller with the user identity name. userOnlineController = new UserOnlineController(true, userIdentityName, null); } // Return the new user controller instance. return(userOnlineController); }
/// <summary> /// Release the current session state data from memory. /// </summary> public static void ReleaseAll() { if (UserOnlineController.CurrentUser != null) { // Cleanup the cuurrent session state data // from the cache. MemberInfo memberInfo = new MemberInfo(); memberInfo.UniqueHashcode = UserOnlineController.CurrentUser.UniqueHashcode; memberInfo.UserIdentityName = UserOnlineController.CurrentUser.UserIdentityName; RuntimeCache.Remove(UserOnlineController.CurrentUser.UniqueHashcode); RemoveUserFromCache(memberInfo); } // Cleanup the current session state. UserOnlineController.CurrentUser = null; }