C# 会话对象在页面重定向时未返回

C# 会话对象在页面重定向时未返回,c#,asp.net,vb.net,session,C#,Asp.net,Vb.net,Session,因此,在Default.master.cs PageLoad中,我有以下内容: contObj = Session["Contributor"] == null ? null : (Contributor)Session["Contributor"]; if (contObj == null) { Session["Contributor"] = new Contributor { ID = id, Name = name, Ema

因此,在Default.master.cs PageLoad中,我有以下内容:

contObj = Session["Contributor"] == null ? null : (Contributor)Session["Contributor"];
if (contObj == null)
{
    Session["Contributor"] = new Contributor
    {
        ID = id,
        Name = name,
        Email = email
    };
}
在Default.aspx.cs中,我试图通过在按钮单击事件中执行此操作来获取对象:\

contObj = (Contributor)Session["Contributor"];
但是,这会导致以下异常! 对象引用未设置为对象的实例

我不知道我做错了什么。 你能详细说明一下吗


谢谢

确保您的EnableSessionState=“true”位于default.aspx的页面标记中,我认为这不是问题所在,因为他在按钮的单击事件中检索会话对象。这应该在主页加载页面后触发。感谢Adil的快速响应。但是你能看看克里斯托夫说了什么吗?谢谢。如果在if(Page.IsPostBack)中执行操作,您能否确保集合中的会话变量包含在母版页的
if(!Page.IsPostBack)
内页加载中。那么您正在母版页中获取会话?是的,我正在母版页中获取会话-我是否应该将代码块从母版移到default.aspx?-我应该提到的是,它在Firefox上工作,但在IE上不工作——这是一个非常奇怪的问题。非常奇怪的行为检查页面标记中是否有EnableSessionState=“true”?