Guest User

Guest User

  • Tech Writer
  • 515
  • 47k

About keeping session alive in mvc

Nov 19 2020 12:36 PM
hello,
Hope everyone is doing fine
 
I want to redirect to logout page after session is null or expired.
I am able to do it with Global.asax file with following code : 
I have created Session["LoginCheckSession"] while login or after signup. 
 
public class SessionTimeoutAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContext ctx = HttpContext.Current;
if (HttpContext.Current.Session["LoginCheckSession"] == null)
{
filterContext.Result = new RedirectResult("~/Home/Index");
return;
}
base.OnActionExecuting(filterContext);
}
}
 
But I have TWO different sessions for two different Login pages, one for Admin and Other for User 
With the above code, I can only redirect to either Admin or User Login page 
So is there any way I can use two different sessions on global.asax file and then redirect to a different login page 
Or anyway I can keep the session alive for a long time 
 
thank you in advance

Answers (12)