Response.Write中的NullReferenceException

时间:2013-03-08 19:44:54

标签: c# asp.net nullreferenceexception response.redirect

protected void Btnlogin_Click(object sender, EventArgs e)
{
    BLL.Bll Bll = new BLL.Bll();
    String Result = Bll.Login(TBNomelog.Text, TBPasslog.Text);
    String UserID = Bll.UserID(TBNomelog.Text);
    Session ["IDutil"] = UserID;
    Response.Write(Session["IDultil"].ToString());

    if (Result.Equals("True"))
    {
        MultiView1.ActiveViewIndex = 2;
    }
    else
    {
        MultiView1.ActiveViewIndex = 1;
    }
}

}

当我执行Response.Write时,我得到“NullReferenceException未被用户代码处理” 有任何建议可能会发生这种情况吗?

1 个答案:

答案 0 :(得分:3)

您尝试使用另一个键读取会话对象,而不是您在上面的行中写入(“IDutil”不等于“IDultil”

Session ["IDutil"] = UserID;
Response.Write(Session["IDultil"].ToString()); // Session["IDultil"] will be null