1

[.Net Core 3.1]

I need to set SessionTimeout redirect to login page. How can I use HttpContext.Current? This is my code

using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Http;

namespace DemoMVCLogin.Class
{
  public class SessionManagement
  {

  }


  public class SessionTimeoutAttribute : ActionFilterAttribute
  {
      public override void OnActionExecuting(ActionExecutingContext filterContext)
      {
        HttpContext httpContext = HttpContext.Current;
        base.OnActionExecuting(filterContext);
      }
  }

}

1 Answer 1

3

HttpContext.Current is no longer part of .Net Core.

Access the HttpContext via ActionContext.HttpContext property

Gets or sets the HttpContext for the current request.

public class SessionTimeoutAttribute : ActionFilterAttribute {
    public override void OnActionExecuting(ActionExecutingContext filterContext) {
        HttpContext httpContext = filterContext.HttpContext;
        base.OnActionExecuting(filterContext);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.