为将对象引用到实例[超怪问题]
我在LOGIN的时候给SESSION赋了N个值代码如下(运行通过/经测试 值传进了SEESSION):
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Label1.Text = string.Empty;
if (string.Compare(Request.Cookies["CheckCode"].Value.ToLower(), txtYZM.Value.ToLower()) != 0)
{
Image5.Visible = true;
Label1.Text = "验证码错误,请输入正确的验证码";
return;
}
else
{
SqlConnection LoginCon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["alockarConnectionString"].ToString());
LoginCon.Open();
SqlCommand cmd = new SqlCommand("select * from users where UserName='" + txtUserName.Value.Trim() + "'", LoginCon);
cmd.CommandType = CommandType.Text;
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
string Manage = reader["Manage"].ToString();
string Vip = reader["Vip"].ToString();
string Grade = reader["Grade"].ToString();
int UserID = reader.GetInt32(0);
string PassWord = reader["PassWord"].ToString();
string PassWord0 = txtPassword.Value.Trim();
if (PassWord == PassWord0)
{
Session["UserID"] = UserID;
Session["UserName"] = txtUserName.Value.Trim();
Session["Grade"] = Grade;
Session["Vip"] = Vip;
Session["Manage"] = Manage;
Response.Write(ccObj.MessageBoxUrl("登陆成功!", "../Default.aspx"));
}
else
{
Response.Write(ccObj.MessageBox("您输入的用户名和密码不正确,请重新输入!"));
}
}
else
{
Response.Write(ccObj.MessageBox("您输入的用户名和密码不正确,请重新输入!"));
}
/*else
{
SqlConnection LoginCon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["alockarConnectionString"].ToString());
SqlCommand LoginCmd = new SqlCommand("ValidateLogin", LoginCon);
LoginCmd.CommandType = CommandType.StoredProcedure;
LoginCmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = txtUserName.Value.Trim();
LoginCmd.Parameters.Add("CryptPassword", SqlDbType.VarChar).Value = txtPassword.Value.Trim();
LoginCon.Open();
int userid = Convert.ToInt32(LoginCmd.ExecuteScalar());
LoginCon.Close();
if (userid <= 0)
{
Response.Write(ccObj.MessageBox("您输入的用户名和密码不正确,请重新输入!"));
}
else
{
Session["UserName"] = txtUserName.Value.Trim();
Response.Write(ccObj.MessageBoxUrl("登陆成功!", "../Default.aspx"));
}
}*/
}
}
然后我在别的页判断SEESION的值时 出现错误
代码如下:
if (!IsPostBack)
{
if (Session["Manage"].ToString() != "普通用户" || Session["Manage"].ToString() != "超级用户")//?
{
LinkButton9.Visible = true;
}
else
{
LinkButton9.Visible = false;
}
}
单步调试 Session["Manage"]有值 但的确是以上判断出错
......求高手帮助解决
错误提示:
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 20: if (!IsPostBack)
行 21: {
行 22: if (Session["Manage"].ToString() != "普通用户" || Session["Manage"].ToString() != "超级用户")//?
行 23: {
行 24: LinkButton9.Visible = true;
--------------------编程问答-------------------- 你写英文的值试下. --------------------编程问答-------------------- if (Session["Manage"] != null && (Session["Manage"].ToString() != "普通用户" || Session["Manage"].ToString() != "超级用户"))
补充:.NET技术 , .NET Framework