private void StartNewSession(HttpContextBase context, int?userID)
        {
            if (userID.HasValue)
            {
                var oldUserSession = _userSessionRepository.GetSessionIDByUserID(userID.Value);
                if (oldUserSession != null)
                {
                    EndAndDeleteSession(oldUserSession);
                }
            }
            var random    = new Random();
            var sessionID = random.Next(int.MinValue, int.MaxValue);

            context.Response.Cookies.Set(new HttpCookie(_sessionIDCookieName, sessionID.ToString()));
            _securityLogService.CreateLogEntry(null, userID, context.Request.UserHostAddress, sessionID.ToString(), SecurityLogType.UserSessionStart);
            _userSessionRepository.CreateSession(sessionID, userID, DateTime.UtcNow);
        }
Esempio n. 2
0
        private int StartNewSession(int?userID, string ip, Action <int> createSession)
        {
            if (userID.HasValue)
            {
                var oldUserSession = _userSessionRepository.GetSessionIDByUserID(userID.Value);
                if (oldUserSession != null)
                {
                    EndAndDeleteSession(oldUserSession);
                }
            }
            var random    = new Random();
            var sessionID = random.Next(int.MinValue, int.MaxValue);

            _securityLogService.CreateLogEntry(null, userID, ip, sessionID.ToString(), SecurityLogType.UserSessionStart);
            _userSessionRepository.CreateSession(sessionID, userID, DateTime.UtcNow);
            createSession(sessionID);
            return(sessionID);
        }