Azm Amn

Azm Amn

  • NA
  • 108
  • 16.8k

Provide different login pages for different designation

Aug 1 2015 8:20 PM
I want users to be redirected to another page after login based on their designation. I.E. If Circle Inspector redirect to a page or if Sub Inspector or Constable Redirect to another Page.
 
I created a stored procedure for Login only but didnt create for different designations.
 
Behind 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.SqlClient;
using System.Data;
namespace Final_Project
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=AHZAM-PC\\AHZAM;Initial Catalog=Police;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
}
public int Validate_Login(String Username, String Password)
{
SqlCommand cmdselect = new SqlCommand();
cmdselect.CommandType = CommandType.StoredProcedure;
cmdselect.CommandText = "lgin";
cmdselect.Parameters.Add("@Username", SqlDbType.VarChar, 50).Value = Username;
cmdselect.Parameters.Add("@Password", SqlDbType.VarChar, 50).Value = Password;
cmdselect.Parameters.Add("@OutRes", SqlDbType.Int, 4);
cmdselect.Parameters["@OutRes"].Direction = ParameterDirection.Output;
cmdselect.Connection = con;
int Results = 0;
try
{
con.Open();
cmdselect.ExecuteNonQuery();
Results = (int)cmdselect.Parameters["@OutRes"].Value;
}
catch (SqlException ex)
{
lblMessage.Text = ex.Message;
}
finally
{
cmdselect.Dispose();
if (con != null)
{
con.Close();
}
}
return Results;
}
protected void btnlogin_Click(object sender, EventArgs e)
{
if ((txtUsername.Text == "Admin") && (txtPassword.Text == "@dMiN"))
{
Response.Redirect("Admin CP.aspx");
}
if (HttpContext.Current.User.IsInRole("Admin"))
{
Response.Redirect("Admin CP.aspx");
}
else if (HttpContext.Current.User.IsInRole("Constable"))
{
Response.Redirect("View FIR.aspx");
}
int Results = 0;
if (txtUsername.Text != string.Empty && txtPassword.Text != string.Empty)
{
Results = Validate_Login(txtUsername.Text.Trim(), txtPassword.Text.Trim());
if (Results == 1)
{
Response.Redirect("User CP.aspx");
}
else
{
lblMessage.Text = "Invalid Login";
lblMessage.ForeColor = System.Drawing.Color.Red;
//Dont Give too much information this might tell a hacker what is wrong in the login
}
}
else
{
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "Please make sure that the username and the password is filled in";
}
}
protected void btnRegister_Click(object sender, EventArgs e)
{
Response.Redirect("Register.aspx");
}
}
}
Please help i need users to be redirect depending on their designation. 
 

Answers (3)