saba naaz

saba naaz

  • NA
  • 15
  • 3.2k

login by different role

Apr 28 2018 11:10 AM
Code for login-----
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{}
string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string str, Email, Password;
SqlCommand com;
SqlDataAdapter sqlda;
DataTable dt;
int RowCount;
protected void ValidateUser(object sender, AuthenticateEventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "Select Email,Password,Role from Users";
com = new SqlCommand(str);
sqlda = new SqlDataAdapter(com.CommandText, con);
dt = new DataTable();
sqlda.Fill(dt);
RowCount = dt.Rows.Count;
for (int i = 0; i < RowCount; i++)
{
Email= dt.Rows[i]["Email"].ToString();
Password = dt.Rows[i]["Password"].ToString();
if (Email==Login1.UserName && Password==Login1 .Password )
{
Session["Email"] = Email;
if (dt.Rows[i]["Role"].ToString() == "Admin")
Response.Redirect("Admin.aspx");
else if (dt.Rows[i]["Role"].ToString() == "User")
Response.Redirect("~/member.aspx");
}
else
{
Response.Redirect("Default.aspx");
}
}
}
}
 
table
 
UserId     Firstname     Lastname     Email                                   Contact           Password     Role
1              saba              haque           [email protected]     9876543210     12345        User
 
after entering the value in login form it opens Default.aspx..
not open member page
please help me

Answers (5)