protected void Button1_Click(object sender, EventArgs e)
{
string tccuser = this.tccuser.Text.ToString();
string tccpass = this.tccpass.Text.ToString();
string cmdstring = "select * from tcclogin where tccuser = '"+tccuser+"' and tccpass='"+tccpass+"'";
SqlConnection connection = new SqlConnection(connstring);
SqlCommand sqlcmd = new SqlCommand(cmdstring, connection);
SqlDataReader rd;
connection.Open();
rd = sqlcmd.ExecuteReader();
if (rd.Read())
{
Session["username"] = tccuser;
Response.Redirect("index.aspx");
}
else
{
this.Label17.Text = "Wrong username or password!";
}
}
{
string tccuser = this.tccuser.Text.ToString();
string tccpass = this.tccpass.Text.ToString();
string cmdstring = "select * from tcclogin where tccuser = '"+tccuser+"' and tccpass='"+tccpass+"'";
SqlConnection connection = new SqlConnection(connstring);
SqlCommand sqlcmd = new SqlCommand(cmdstring, connection);
SqlDataReader rd;
connection.Open();
rd = sqlcmd.ExecuteReader();
if (rd.Read())
{
Session["username"] = tccuser;
Response.Redirect("index.aspx");
}
else
{
this.Label17.Text = "Wrong username or password!";
}
}
本文介绍了一个使用ASP.NET进行简单登录验证的例子。通过获取用户输入的用户名和密码,利用SQL查询来验证用户身份,并使用Session来管理已验证用户的会话状态。如果验证失败,则向用户显示错误消息。
1231

被折叠的 条评论
为什么被折叠?



