using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class _Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
Db NewsXT = new Db();
//密码使用MD5加密
string Password = FormsAuthentication.HashPasswordForStoringInConfigFile(Pwd.Text.ToString(), "MD5"); //textBox中得到的密码 MD5加密 SqlConnection Conn = new SqlConnection(NewsXT.strConn); SqlCommand Cmd = new SqlCommand("select * from Admin where UserAdmin='" + Uid.Text + "' and UserPwd = '" + Pwd.Text + "' ", Conn); Conn.Open(); //Open :打开 SqlDataReader Dr = Cmd.ExecuteReader(); if (Uid.Text != "" && Pwd.Text != "") //如果 Uid.Text 的值不等于空 并且 Pwd.Text 的值不等于空
{
if (Dr.Read()) // Read : 读出
{
if (Chkcode.Text == Session["Code"].ToString())
{
Session["Admin"] = "Admin";
Response.Write("<script>alert('登陆成功!');history.go(-1);</script>");
Response.Redirect("Adminindex.aspx");
}
else //否则
{
Response.Write("<script>alert('验证码错误!');history.go(-1);</script>"); //执行 (验证码错误)
Chkcode.Focus(); //焦点停留在当前窗体的文本框内 Focus()是说把鼠标的光标放到控件上
}
}
else //否则
{
Response.Write("<script>alert('用户名或密码错误!');history.go(-1);</script>"); //执行 (用户名或密码错误)
}
}
else //否则
{
Response.Write("<script>alert('请输入用户名和密码!');history.go(-1);</script>"); //执行 (请输入用户名或密码)
}
}
}提示错误为:
“/NewsXT”应用程序中的服务器错误。
--------------------------------------------------------------------------------未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 35: if (Dr.Read()) // Read : 读出
行 36: {
行 37: if (Chkcode.Text == Session["Code"].ToString())
行 38: {
行 39: Session["Admin"] = "Admin";
源文件: e:\aspnet\NewsXT\Admin\Login.aspx.cs 行: 37 这个是哪出了问题啊 帮帮忙啊 我是新手、及及及......
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class _Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
Db NewsXT = new Db();
//密码使用MD5加密
string Password = FormsAuthentication.HashPasswordForStoringInConfigFile(Pwd.Text.ToString(), "MD5"); //textBox中得到的密码 MD5加密 SqlConnection Conn = new SqlConnection(NewsXT.strConn); SqlCommand Cmd = new SqlCommand("select * from Admin where UserAdmin='" + Uid.Text + "' and UserPwd = '" + Pwd.Text + "' ", Conn); Conn.Open(); //Open :打开 SqlDataReader Dr = Cmd.ExecuteReader(); if (Uid.Text != "" && Pwd.Text != "") //如果 Uid.Text 的值不等于空 并且 Pwd.Text 的值不等于空
{
if (Dr.Read()) // Read : 读出
{
if (Chkcode.Text == Session["Code"].ToString())
{
Session["Admin"] = "Admin";
Response.Write("<script>alert('登陆成功!');history.go(-1);</script>");
Response.Redirect("Adminindex.aspx");
}
else //否则
{
Response.Write("<script>alert('验证码错误!');history.go(-1);</script>"); //执行 (验证码错误)
Chkcode.Focus(); //焦点停留在当前窗体的文本框内 Focus()是说把鼠标的光标放到控件上
}
}
else //否则
{
Response.Write("<script>alert('用户名或密码错误!');history.go(-1);</script>"); //执行 (用户名或密码错误)
}
}
else //否则
{
Response.Write("<script>alert('请输入用户名和密码!');history.go(-1);</script>"); //执行 (请输入用户名或密码)
}
}
}提示错误为:
“/NewsXT”应用程序中的服务器错误。
--------------------------------------------------------------------------------未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 35: if (Dr.Read()) // Read : 读出
行 36: {
行 37: if (Chkcode.Text == Session["Code"].ToString())
行 38: {
行 39: Session["Admin"] = "Admin";
源文件: e:\aspnet\NewsXT\Admin\Login.aspx.cs 行: 37 这个是哪出了问题啊 帮帮忙啊 我是新手、及及及......
Session在哪里赋值了?