I want to add role wise login. But not working.
How to do this
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.Configuration;
using System.Data.SqlClient;
using System.Web.Security;
namespace User_Login_CS
{
public partial class Login : System.Web.UI.Page
{
protected void ValidateUser(object sender, EventArgs e)
{
int userId = 0;
int PROJECT_ID;
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("Validate_User"))
{
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Username", Login1.UserName);
cmd.Parameters.AddWithValue("@Password", Login1.Password);
cmd.Connection = con;
con.Open();
userId = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
}
switch (userId)
{
case -1:
Login1.FailureText = "Username and/or password is incorrect.";
break;
case -2:
Login1.FailureText = "Account has not been activated.";
break;
case 1003:
string userId = Login1.UserName;
Response.Redirect(string.Format("~/Index.aspx?EmpId={0}", userId));
break;
case 1004:
Response.Redirect("nwitpnl.aspx");
break;
case 1005:
Response.Redirect("Elec_Twn_Comp.aspx");
break;
case 1006:
Response.Redirect("Elec_Plnt_Comp.aspx");
break;
case 1007:
Response.Redirect("Cvl_Twn_Comp.aspx");
break;
case 1008:
Response.Redirect("Cvl_Plnt_Comp.aspx");
break;
case 1009:
Response.Redirect("Hr_Comp.aspx");
break;
default:
FormsAuthentication.RedirectFromLoginPage(Login1.UserName, Login1.RememberMeSet);
break;
}
}
}
}
}