我有登录页面,用户有3个用户类型。从登录im capturig用户ID和密码。但我想检查user_type字段,并根据登录后重定向到不同的页面。请指教我
答案 0 :(得分:0)
如果你想从DB读取,你必须做这样的事情。
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TestConString"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("SELECT User_Type FROM [User] WHERE User_Id =@userid and User_Password=@password", con);
cmd.Parameters.AddWithValue("@userid", Convert.ToInt32(txtUserName.Text));
cmd.Parameters.AddWithValue("@password", txtPassword.Text);
var reader = cmd.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
string userType = reader.GetString(0);
Session["USER_ID"] = txtUserName.Text;
Response.Redirect("Dashboard.aspx");
}
else
{
Response.Write("Login Failed");
}
答案 1 :(得分:0)
下面是使用从数据库返回的User_Type的示例:
if (dt.Rows.Count > 0)
{
Session["USER_ID"] = txtUserName.Text;
switch((string)dt.Rows[0]["User_Type"])
{
case "UserType1":
Response.Redirect("UserType1Dashboard.aspx");
break;
case "UserType1":
Response.Redirect("UserType2Dashboard.aspx");
break;
case "UserType1":
Response.Redirect("UserType3Dashboard.aspx");
break;
default:
Response.Redirect("Dashboard.aspx");
break;
}
}
else
{
Response.Write("Login Failed");
}