1

i am trying to store an object in session..

in one controller, i create the object and put it in session.

MyObject _o = new MyObject();
Session["MyObject"] = _o;
MyObject _oo = (MyObject)Session["MyObject"]; // added for testing purposes, is not null

i can retrieve the object from session just fine from within same controller.

then i redirect to an action method on another controller, and in a base controller i try to access ControllerContext.HttpContext.Session and it is always null.

if(_obj == null)
{
    _obj = (MyObject)Session["MyObject"]; // always null
}

any ideas why?

thanks :-)

3
  • Wait, is MyObject an object or a type? It's used as an object the first time, but using it as a cast type the second time. Commented Mar 10, 2010 at 20:28
  • i just changed object name to clear things up, thanks Commented Mar 10, 2010 at 20:31
  • Not enough info in your question. From what you describe it should work fine. Commented Mar 10, 2010 at 21:59

1 Answer 1

1

When access Session object?

HttpContext initialized after Controller.Initialize().

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.