Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
3.33/5 (3 votes)
See more:
In database i have username,password,department,..
while login time i have to check username and department(in department i have fields are IT, employee, HR )
if username and department(IT) it should b redirect to It Page only
if username and department(Hr) it should b redirect to HR Page only
if username and department(Employee) it should b redirect to Employee Page only

and login.aspx i have only two filed user name and password..

following is my coding

C#
public class LogIn
{
SqlDataAdapter adp;
DataSet ds;
public LogIn()
{

}
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrin gs["ConnectionString"].ConnectionString.ToString());

public DataSet select(string s)
{
adp = new SqlDataAdapter(s, cn);
ds = new DataSet();
adp.Fill(ds);
return ds;
}
}

in
login.aspx.cs
C#
protected void btn_login_Click(object sender, EventArgs e)
{
DataSet DS = new DataSet();
string s = "select depertment from checkuser where user_name='" + txtusername.Text + "' and password='" + txtpassword.Text + "'";
DS = objlog.select(s);

if (DS.Tables[0].Rows.Count > 0)
{
Session["username"] = txtusername.Text;
Response.Redirect("Home.aspx");
}

}

m not getting how i wl do this..
reply asap.. m waiting
thank You
Posted
Updated 22-Dec-12 0:10am
v2

C#
DataSet DS = new DataSet();

    string s = "select depertement from tb where username='" + TextBox1.Text + "' and password='" + TextBox2.Text + "'";

    DS = objlog.select(s);


    if (DS.Tables[0].Rows.Count > 0)
    {

        Session["username"] = TextBox1.Text;
        Session["depertementname"] = DS.Tables[0].Rows[0]["depertement"].ToString().ToUpper();

        if (Session["depertementname"].ToString() == ("HR"))
        {

            Response.Redirect("HrHome.aspx");

        }

        else
        {

            Response.Redirect("Home.aspx");

        }


    }
}
 
Share this answer
 
Namskar(Hi),


C#
protected void btn_login_Click(object sender, EventArgs e)
{
DataSet DS = new DataSet();
string s = "select depertment from checkuser where user_name='" + txtusername.Text + "' and password='" + txtpassword.Text + "'";
DS = objlog.select(s);

if (DS.Tables[0].Rows.Count > 0)
{
Session["username"] = txtusername.Text;
   if(DS.Tables[0].Rows[0][0].ToString()=="IT")
    {
      Response.Redirect("IT.aspx");
    }
   else if(DS.Tables[0].Rows[0][0].ToString()=="Employee")
    {
      Response.Redirect("Employee.aspx");
    }
   else
    {
      Response.Redirect("Hr.aspx");
    }


}

}
 
Share this answer
 
Comments
Jay Ahuja 24-Dec-12 1:18am    
Thanx a lot.. :) finally i got perfect coding :)
1. You have to store the user type in user table.
2. Verify that username and password are correct.
3. Get user type from database.
4. Open the appropriate page using if-else.

This is too basic solution.
Hope it helps.........

In case you are not satisfied with the solution please let me know.
I will tell you the other way.

[Edit]Shouting removed[/Edit]
 
Share this answer
 
v2
Comments
Jay Ahuja 22-Dec-12 3:00am    
hello sir, thanx for ur help
the 1st three step m already done wen m trying 4th one itz redirecting to same page only can u please help me for this
AnkitGoel.com 22-Dec-12 3:03am    
send your code by which u are redirecting users to different pages
Jay Ahuja 22-Dec-12 3:14am    
if (DS.Tables[0].Rows.Count > 0)
{
Session["username"] = txtusername.Text;
if (Session["username"].ToString() == ("Emplpoyee"))
{
Response.Redirect("Home.aspx");
}
else
{
Response.Redirect("HrHome.aspx");
}

}
AnkitGoel.com 22-Dec-12 3:17am    
in this case which page are u getting redirected?

Also, check the spell mistake -emplpoyee- should be 'employee-
Jay Ahuja 22-Dec-12 3:19am    
home.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900