title: Redirect to Login Page if Session expired in ASP MVC net core
body: <p>I am working in ASP net core MVC Application. My aim is to redirect to the login page if the session expired.
  In my case, I am using several ajax call to load a page. Sometimes it is redirecting properly, but sometimes it is not doing so. </p>
  
  <pre><code> public class CheckSessionIsAvailable : ActionFilterAttribute
  {
      public override void OnActionExecuting(ActionExecutingContext filterContext)
      {
          base.OnActionExecuting(filterContext);
  
          if (filterContext.HttpContext == null || filterContext.HttpContext.Session.GetString("UserID") == null)
          {
              //return RedirectToAction("Index", "Login");
  
              filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new
              {
                  controller = "Login",
                  action = "Index"
              }));
          }
      }
  }
  </code></pre>
  
  <p>Created an action filter <strong>CheckSessionIsAvailable</strong> and associated it with all the controllers.</p>
  
  <pre><code>[CheckSessionIsAvailable]
  public class TestController : Controller
  {
  
      public IActionResult Index()
      {
          return View();
      }
  }
  </code></pre>
  
  <p>Am I doing anything wrong while creating <strong>Action Filter</strong> ?</p>