Access Session.SessionID in ActionFilterAttribute
-
26-05-2021 - |
Question
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow