asp.net - mvc - onactionexecuting



訪問ActionFilterAttribute中的Session.SessionID (1)

你嘗試過嗎?

filterContext.HttpContext.Session.SessionId

我已經創建了控制器屬性,並希望讀取SessionId,但得到錯誤“ An object reference is required for the non-static field, method, or property ”。 從控制器屬性訪問會話對象的最佳方法是什麼?

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);
    }
}