Monday, 9 September 2013

Not able to use Sessions in ASP MVC3

Not able to use Sessions in ASP MVC3

I start the page from a landing page where I call a function from a
Controller, to assign values to some sessions. But I seem to not be able
to use them, as I get Object reference not set to an instance of an
object. exception on the first line of the body of the following function:
public void assignNewUserToSession(string currentButtonID, string user,
string app)
{
Session["buttonID"] = currentButtonID;
Session["userID"] = user;
Session["appID"] = app;
}
This exception is usually thrown when one is using a variable that has not
been initialized, that is = to null or nothing. But as far as I know,
Sessions don't have to be initialized in any other way than I have done it
in the code above.
Here is where I call the upper function:
public void landingPage()
{
FC.assignNewUserToSession("34", "asd", "gsds");
Media(); // This is the view Controller for another page.
}
What might be the problem ?

No comments:

Post a Comment