title: Creating different views for different user type on login (ASP.net)
body: <p>I am in need of help creating different views for different user type (Students, Teacher, Admin, etc.). After successful login, I want to redirect the users to their specific view. Currently, I am able to verify their user type and login credentials directly from the database, if its successful, it redirects to the default layout view. </p>
  
  <p>This is my login.aspx for the login form. </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Data;
  using System.Data.SqlClient;
  
  
  namespace LoginQuery
  {
      public partial class Login : System.Web.UI.Page
      {
          SqlCommand cmd = new SqlCommand();
          SqlConnection con = new SqlConnection();
          SqlDataAdapter sda = new SqlDataAdapter();
          DataSet ds = new DataSet();
  
          protected void Page_Load(object sender, EventArgs e)
          {
              con.ConnectionString = "Data Source=[Connection String]";
          }
  
          protected void BtnLogin_Click(object sender, EventArgs e)
          {
              con.Open();
              cmd.CommandText = "SELECT PersonType FROM Person where Username='" + txtUsername.Text + "' and Password='" + txtPassword.Text + "' and PersonType='" + userType.SelectedValue + "'";
              cmd.Connection = con;
              sda.SelectCommand = cmd;
              sda.Fill(ds, "Person");
              con.Close();
              if (ds.Tables[0].Rows.Count &gt; 0)
              {
                  Response.Redirect(url: "http://localhost:56061/");
              }
              else
              {
                  cmd.CommandText = "SELECT PersonType FROM Person where Username='" + txtUsername.Text + "' and Password='" + txtPassword.Text + "'";
                  cmd.Connection = con;
                  sda.SelectCommand = cmd;
                  sda.Fill(ds, "Person");
  
                  if (ds.Tables[0].Rows.Count &gt; 0)
                  {
                      Label1.Text = "Invalid User Type. Please Try Again!";
                  }
                  else
                  {
  
                      Label1.Text = "Invalid User Type, Username or Password. Please Try Again!";
                  }
              }
          }
  
          protected void UserType_SelectedIndexChanged(object sender, EventArgs e)
          {
              ImageDef.ImageUrl = "Images/student.png";
              {
                  if (userType.SelectedValue == "Student")
                  {
                      ImageDef.ImageUrl = "Images/student.png";
                  }
                  else if (userType.SelectedValue == "Teacher")
                  {
                      ImageDef.ImageUrl = "Images/teacher.png";
                  }
                  else if (userType.SelectedValue == "Counselor")
                  {
                      ImageDef.ImageUrl = "Images/counselor.png";
                  }
                  else if (userType.SelectedValue == "Parent")
                  {
                      ImageDef.ImageUrl = "Images/parent.png";
                  }
                  else if (userType.SelectedValue == "Principal")
                  {
                      ImageDef.ImageUrl = "Images/principal.png";
                  }
                  else if (userType.SelectedValue == "Admin")
                  {
                      ImageDef.ImageUrl = "Images/admin.png";
                  }
                  else
                  {
                      ImageDef.ImageUrl = "Images/student.png";
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>I use response.redirect to my localhost page. </p>