asp.netasp.net-mvcsessioncontrolleractionfilterattribute

Access Session.SessionID in ActionFilterAttribute


I have created Controller Attribute and would like to read SessionId but get error "An object reference is required for the non-static field, method, or property". What is the best method to access session object from controller attribute?

public class DetectChangesAttribute :ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        //I get error on Controller.Session.SessionID
        ConversionQueueModel.Remove(Controller.Session.SessionID, "");
        base.OnActionExecuting(filterContext);
    }
}

Solution

  • Have you tried this?

    filterContext.HttpContext.Session.SessionId