user1027620
user1027620

Reputation: 2785

Session Object Not Returning On Page Redirect

So In Default.master.cs PageLoad I have the following:

contObj = Session["Contributor"] == null ? null : (Contributor)Session["Contributor"];
if (contObj == null)
{
    Session["Contributor"] = new Contributor
    {
        ID = id,
        Name = name,
        Email = email
    };
}

In Default.aspx.cs I'm trying to get the object by doing this on a button click event:\

contObj = (Contributor)Session["Contributor"];

However this is causing the following exception! object reference not set to an instance of an object.

I don't see what I'm doing wrong. Could you please elaborate?

Thanks!

Upvotes: 0

Views: 134

Answers (1)

Adil
Adil

Reputation: 148180

Make sure that your EnableSessionState="true" in the page tag of default.aspx

Upvotes: 2

Related Questions