Access Session.SessionID in ActionFilterAttribute
-
26-05-2021 - |
Frage
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);
}
}
Lösung
Have you tried this?
filterContext.HttpContext.Session.SessionId
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow