SqlConnection con= new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from login where Email =@username and Password=@password and Activated_User=1 and User_Type=1", con);
cmd.Parameters.AddWithValue("@username", Login1.UserName);
cmd.Parameters.AddWithValue("@password", Login1.Password);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable ds = new DataTable();
da.Fill(ds);
if (ds.Rows.Count > 0)
{
Session["UID"] = Login1.UserName;
Response.Redirect("dashboard.aspx");
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");
}
嗨,我是 .NET 的新手,上面的代码用于登录页面。我想将管理员和用户分别重定向到不同的页面(dashboard.aspx 和 user-dashboard.aspx)。User_Type=1 表示 Admin,如果为 2,则表示 USER。