1

I have an attribute that fired when any request recieve to my asp mvc application.

public class AllActionsAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var session = Session["mySession"]; //it' doesn't work
    }
}

Is there any way to check Session in OnActionExecuting() function?

2
  • What does "it doesn't work" mean? is the Session null? is the value for your key empty? does this occur only the first time you statrt up your app? Commented Aug 25, 2017 at 15:11
  • The name Session does not exist in the current context. No it occur in any request. Commented Aug 25, 2017 at 16:06

1 Answer 1

3

Session can be accessed through the filterContext

Session is a controller property that wraps access to the HttpContext.Session.

There is no Session property in a action filter, you need to look at Session through the filterContext.

filterContext.HttpContext.Session
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.