public async Task SignOut() { var session = await _sessionManager.GetSession(); await _sessionProvider.Clear(); await _httpContextAccessor.HttpContext.SignOutAsync(); // keep essential variables if the user continues to browse around await _sessionProvider.Set(SessionConstants.IsDebug, session.IsDebug); await _sessionProvider.Set(SessionConstants.SessionLogId, session.SessionLogId); // keeps state for the duration of the current request }
public async Task <GetSessionResponse> GetSession() { var response = new GetSessionResponse(); // get or create a new session var session = await _sessionProvider.Get <SessionEntity>(SessionConstants.SessionEntity); if (session == null) { // flush any authenticated cookies in the event the application restarts await _httpContextAccessor.HttpContext.SignOutAsync(); await _sessionProvider.Clear(); var userAgent = _httpContextAccessor.HttpContext.Request.Headers[HeaderNames.UserAgent].FirstOrDefault(); using (var uow = _uowFactory.GetUnitOfWork()) { response.SessionEntity = await uow.SessionRepo.CreateSession(new Repositories.DatabaseRepos.SessionRepo.Models.CreateSessionRequest() { User_Agent = userAgent, Created_By = ApplicationConstants.SystemUserId }); uow.Commit(); } await _sessionProvider.Set(SessionConstants.SessionEntity, response.SessionEntity); return(response); } response.SessionEntity = session; var sessionLogId = await _sessionProvider.Get <int?>(SessionConstants.SessionLogId); if (sessionLogId != null) { response.SessionLogId = sessionLogId.Value; } var isDebug = await _sessionProvider.Get <bool?>(SessionConstants.IsDebug); if (isDebug != null) { response.IsDebug = isDebug ?? false; } return(response); }