public override void OnPageHandlerSelected(PageHandlerSelectedContext filterContext) { string tagName = "[Enrollments][CreateModel][OnPageHandlerSelected]"; ApplicationUser appUser = _userManager.GetUserAsync(HttpContext.User).Result; string pageRedirect = _sessionCookieService.DeterminePageRedirect(appUser.UserName, tagName); if (pageRedirect != null) { filterContext.HttpContext.Response.Redirect(pageRedirect); return; } _logger.LogInformation(tagName + " => Refreshing SessinCookie for '" + appUser.UserName + "'"); _sessionCookieService.RefreshSessionCookie(appUser.UserName); }
public override void OnPageHandlerSelected(PageHandlerSelectedContext filterContext) { ApplicationUser appUser = _userManager.GetUserAsync(HttpContext.User).Result; SessionCookie sessionCookie = _sessionCookieService.RetrieveSessionCookie(appUser.UserName); if (sessionCookie == null) { StringBuilder sb = new StringBuilder("[Enrollments][IndexModel][OnPageHandlerSelected] => SessionCookie for '"); sb.Append(appUser.UserName); sb.Append("' NOT FOUND. Redirecting to Login page."); _logger.LogInformation(sb.ToString()); filterContext.HttpContext.Response.Redirect("/Account/LoginPrep"); return; } if (DateTime.Now > sessionCookie.LastAccessedOn.AddMinutes(30)) { StringBuilder sb = new StringBuilder("[Enrollments][IndexModel][OnPageHandlerSelected] => SessionCookie for '"); sb.Append(appUser.UserName); sb.Append("' HAS EXPIRED. It was last accessed on "); sb.Append(sessionCookie.LastAccessedOn); if (DateTime.Now > sessionCookie.LastAccessedOn.AddHours(2)) { sb.Append(". Redirecting to Login page."); _logger.LogInformation(sb.ToString()); filterContext.HttpContext.Response.Redirect("/Account/LoginPrep"); return; } else { sb.Append(". Redirecting to SessionTimeout page."); _logger.LogInformation(sb.ToString()); filterContext.HttpContext.Response.Redirect("/Account/SessionTimeout"); return; } } _logger.LogInformation("[Enrollments][IndexModel][OnPageHandlerSelected] => Refreshing SessinCookie for '" + appUser.UserName + "'"); _sessionCookieService.RefreshSessionCookie(appUser.UserName); }