在ActionFilterAttribute中访问Session.SessionID

时间:2012-03-26 14:41:43

标签: asp.net asp.net-mvc session controller actionfilterattribute

我创建了控制器属性,想要读取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);
    }
}

1 个答案:

答案 0 :(得分:10)

你试过这个吗?

filterContext.HttpContext.Session.SessionId