title: How do I redirect when sessions timeout on .net core mvc
body: <p>I have a little bit of a problem. I'm new to .net core. How do i write a middleware to check my current context and if the session is timeout to redirect to the login page.</p>
  
  <p>I have this action result.</p>
  
  <pre><code>public async Task&lt;IActionResult&gt; Index()
      {
          var product = await productRepository.GetAll();
          ViewBag.Title = "List Of Products";
          return View(product);
      }
  </code></pre>
  
  <p>Now I want to do something that look like this.</p>
  
  <pre><code>[SessionTimeout] // use this to make my code cleaner.
  public async Task&lt;IActionResult&gt; Index()
      {
          var product = await productRepository.GetAll();
          ViewBag.Title = "List Of Products";
          return View(product);
      }
  </code></pre>
  
  <p>All this examples I find is using .Net and I'm trying to use .Net core.</p>
  
  <p>I created a class and I used the example I found online but it doesn't work.</p>
  
  <pre><code>public class SessionTimeout : ActionFilterAttribute
  {
      public override void OnActionExecuting(ActionExecutingContext filterContext)
      {
          HttpContext ctx = HttpContext.Current;
          if (HttpContext.Current.Session["ID"] == null)
          {
              filterContext.Result = new RedirectResult("~/Home/Login");
              return;
          }
          base.OnActionExecuting(filterContext);
      }
  }
  </code></pre>
  
  <p>I get the error HttpContent.Current doesn't exist. Now I know is because using .Net core, but how do i check if my session is active and if I don't have any session redirect the using to the home page.</p>