设置会话时对象引用错误

时间:2019-06-24 07:30:54

标签: c#

当前,我正在开发一个网站,老实说,我对此并不陌生,我的代码也为空引用错误。有什么问题吗?

[WebMethod]
public string loadApplicantAccount(string email, string pass)
{
    List<emplInfo> mylist = new List<emplInfo>();
    using (mysql.MySqlConnection connection = new mysql.MySqlConnection(connectionString()))
    {
        connection.Open();
        mysql.MySqlCommand cmd = new mysql.MySqlCommand("spLoadApplicantAcc", connection);
        cmd.Parameters.Add("uEmail", mysql.MySqlDbType.VarChar).Value = email;
        cmd.Parameters.Add("uPword", mysql.MySqlDbType.VarChar).Value = pass;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandTimeout = 0;

      mysql.MySqlDataReader dr = cmd.ExecuteReader();

        while (dr.Read())
        {
            mylist.Add(new emplInfo
            {
                Displayname = dr["Displayname"].ToString(),
                FullName = dr["Fullname"].ToString(),
                Access = dr["Usertype"].ToString(),
                Status = Convert.ToInt32(dr["Status"].ToString())

            });
        }
        Session["LoggedUser"] = mylist[0].Displayname;
        if (Session["LoggedUser"] == null)
        {
            Server.Transfer("login.html");
        }
        else {
            Server.Transfer("appHunt_IndexPage.html");
        }
        dr.Close();
        connection.Close();
    }
    JavaScriptSerializer jss = new JavaScriptSerializer();
    string jsn = jss.Serialize(mylist);
    return jsn;
}

存在错误的行在这里Session["LoggedUser"] = mylist[0].Displayname;

这是错误

enter image description here enter image description here

有人可以帮助我吗?

0 个答案:

没有答案