【发布时间】:2014-08-08 11:40:35
【问题描述】:
我在这里尝试创建登录页面。 只有管理员可以访问此页面,当前管理员名称是 akshay。 登录页面cs代码:
string cnn = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString;
MySqlConnection con = new MySqlConnection(cnn);
string IdText = UserName.Text;
string PassText = Password.Text;
MySqlCommand cmd = new MySqlCommand("select * from ab_db.login where user= @user and Pass = @Pass", con);
con.Open();
cmd.Parameters.Add("@user", MySqlDbType.String);
cmd.Parameters["@user"].Value = UserName.Text;
cmd.Parameters.Add("@Pass", MySqlDbType.String);
cmd.Parameters["@Pass"].Value = Password.Text;
MySqlDataReader dr = cmd.ExecuteReader();
dr.Read();
if (dr["user"].ToString().Trim() == IdText && dr["Pass"].ToString().Trim() == PassText)
{
Session["User"] = IdText;
Response.Redirect("~/test2.aspx");
}
else
{
FailureText.Text = "Invalid Username or Password";
}
dr.Close();
con.Close();
我想要安全的页面是 test2。 代码是:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["User"] == "akshay")
{
if (!IsPostBack)
{
// Call FillGridView Method
FillGridView();
}
}
else
{
// No valid login...
Session.Clear();
Response.Redirect("~/myLogin.aspx");
}
}
我遇到了一个我不明白为什么的错误?请帮忙。
错误是-
在调用 Read() 之前访问字段的尝试无效
【问题讨论】:
标签: c# html asp.net authentication