C# 根据执行的查询重定向到不同页面的登录控件
我有两个问题。。我想做的是,如果登录控件在第一个查询表中找到用户名和密码,请将其重定向到卖家页面。。如果在第二个查询表中找到un和pw,则将其重定向到经销商页面。我该怎么做?因为它只检查第一个查询C# 根据执行的查询重定向到不同页面的登录控件,c#,sql,C#,Sql,我有两个问题。。我想做的是,如果登录控件在第一个查询表中找到用户名和密码,请将其重定向到卖家页面。。如果在第二个查询表中找到un和pw,则将其重定向到经销商页面。我该怎么做?因为它只检查第一个查询 protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { var conString = ConfigurationManager.ConnectionStrings["CONST
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
var conString = ConfigurationManager.ConnectionStrings["CONSTRING"].ConnectionString;
SqlConnection con = new SqlConnection(conString);
string user = Login1.UserName;
string pass = Login1.Password;
con.Open();
SqlCommand cmd1 = new SqlCommand("select username, password, status from login where username = '" + user + "' and password = '" + pass + "' and status = 1", con);
string CurrentName;
CurrentName = (string)cmd1.ExecuteScalar();
if (CurrentName != null)
{
Session.Timeout = 1;
Session["un"] = Login1.UserName;
Response.Redirect("sellerlogin.aspx?un=" + Login1.UserName);
}
SqlCommand cmd2 = new SqlCommand("select username, password, status from dealer where username = '" + user + "' and password = '" + pass + "' ", con);
string CurrentNam;
CurrentNam = (string)cmd2.ExecuteScalar();
if (CurrentNam != null)
{
Session.Timeout = 1;
Response.Redirect("dealerlogin.aspx?un="+ Login1.UserName);
}
尝试使用:
Response.End();
return;
使用您的代码:
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
var conString = ConfigurationManager.ConnectionStrings["CONSTRING"].ConnectionString;
SqlConnection con = new SqlConnection(conString);
string user = Login1.UserName;
string pass = Login1.Password;
con.Open();
SqlCommand cmd1 = new SqlCommand("select username, password, status from login where username = '" + user + "' and password = '" + pass + "' and status = 1", con);
string CurrentName;
CurrentName = (string)cmd1.ExecuteScalar();
if (CurrentName != null)
{
Session.Timeout = 1;
Session["un"] = Login1.UserName;
Response.Redirect("sellerlogin.aspx?un=" + Login1.UserName);
Response.End();
return;
}
SqlCommand cmd2 = new SqlCommand("select username, password, status from dealer where username = '" + user + "' and password = '" + pass + "' ", con);
string CurrentNam;
CurrentNam = (string)cmd2.ExecuteScalar();
if (CurrentNam != null)
{
Session.Timeout = 1;
Response.Redirect("dealerlogin.aspx?un="+ Login1.UserName);
Response.End();
return;
}
什么意思是“它只检查第一个查询”?你用过调试器吗?始终使用参数化查询而不是字符串连接!这解决了什么问题?OP说它“只检查第一个查询”genius:o非常感谢:D@Samsam-我很乐意帮助你!请选择我的答案作为正确答案,并投票表决。非常感谢。