我的登录按钮的代码是
protected void LoginButton_Click(object sender, EventArgs e)
{
string cs = WebConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection connection = new SqlConnection(cs))
{
connection.Open();
SqlCommand cmd = new SqlCommand("SELECT [Name], [Password] FROM [dbo].[user]", connection);
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
// something goes there
}
if () // admin authentication
{
Session["User_ID"] = nameTextBox.Text;
Response.Redirect("~/AdminPanel.aspx");
}
else if() // user authentication
{
Session["User_ID"] = nameTextBox.Text;
Response.Redirect("~/UserPanel.aspx");
}
}
}
}
在Login
表格中,我有UserID
,UserName
,Password
列。有nametextBox和passwordTextBox来获取UserName&密码。请帮助我,因为我遇到了用户登录的问题。