2016-07-08 4 views
0

私は乗客とドライバーという2種類のユーザーがいます。同じログインページで2種類のユーザーのログイン

protected void Button1_Click(object sender, EventArgs { 

     SqlConnection con = new SqlConnection(conString); 
     SqlCommand cmd = new SqlCommand(); 


     cmd.CommandText = "SP_SELECT_Login1"; 
     cmd.CommandType = CommandType.StoredProcedure; 
     cmd.Connection = con; 

     cmd.Parameters.AddWithValue("@Email", txtEmail.Text); 
     cmd.Parameters.AddWithValue("@Password", txtPassword.Text); 

     SqlDataAdapter ad = new SqlDataAdapter(); 
     DataSet ds = new DataSet(); 
     ad.SelectCommand = cmd; 
     ad.Fill(ds); 

     if (ds.Tables[0].Rows.Count > 0) 
     { 
      Session["UserId"] = ds.Tables[0].Rows[0]["Reg_id"].ToString(); 
      Session["Username"] = ds.Tables[0].Rows[0]["Fname"].ToString(); 



      Response.Redirect("Profile.aspx"); 
     } 
     else 
     { 
      lblMsg.Text = "Incorrect User and Password or Unverify user"; 
     } 
    } 

答えて

0

質問は非常に明確ではない:どのように私は、乗客のためのasp.net C#で両方のユーザー
ログインページに1つのログインページを作ることができます。あなたがuserAとuserBを持っていて、userA資格を渡した後にdbからuserA情報を取得し、userBの資格情報を書くとuserB情報が得られるので、明確にすることができますか?

1

私が正しく理解している場合は、2種類のユーザーのログインに役立つ1つのログインページがあります。だから、あなたのストアドプロシージャからのページへのサインインがそのUSERTYPEを取得し、

if (ds.Tables[0].Rows.Count > 0) 
    { 
     Session["UserId"] = ds.Tables[0].Rows[0]["Reg_id"].ToString(); 
     Session["Username"] = ds.Tables[0].Rows[0]["Fname"].ToString(); 

     int userType = Convert.ToInt32(ds.Tables[0].Rows[0]["UserType"]); 
     if(userType ==1) // Assume "1" for Driver 
     { 
     Response.Redirect("DriverProfile.aspx"); 
     } 
     else //other than "1"/ driver(As per your query you have only two types of users) 
     { 
      Response.Redirect("PassengerProfile.aspx"); 
     } 
    } 
    else 
    { 
     lblMsg.Text = "Incorrect User and Password or Unverify user"; 
    } 

上記の条件に基づいて、下のように条件を与えながら、毎回のために、ユーザのテーブルでユーザタイプを維持し、一つのことを行うに基づくことができますユーザーの種類に応じて、尊重されたユーザープロファイルにリダイレクトされます。

関連する問題