ASp.net C#.how将不同用户重定向到不同的页面。 [英] ASp.net C#.how to redirect different user to different pages.

查看:112
本文介绍了ASp.net C#.how将不同用户重定向到不同的页面。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据库中我有用户名,密码,部门,..

登录时我必须检查用户名和部门(在部门我有字段是IT,员工,人力资源)

如果用户名和部门(IT)它应该重定向到它只有页面

如果用户名和部门(Hr)它应该b重定向到HR页面

如果用户名和部门(员工)它应该只重定向到员工页面



和login.aspx我只有两个提交的用户名和密码..



以下是我的编码



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

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


in
login.aspx.cs

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没有得到我将如何做到这一点..

回复asap ..等待

谢谢


m not getting how i wl do this..
reply asap.. m waiting
thank You

推荐答案

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");

        }


    }
}


Namskar(Hi),





Namskar(Hi),


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");
    }


}

}


1。您必须将用户类型存储在用户表中。

2.验证用户名和密码是否正确。

3.从数据库获取用户类型。

4.使用if-else打开相应的页面。



这是太基本的解决方案。

希望它有帮助...... ......



如果您对解决方案不满意,请告诉我。

我会告诉你其他的方式。



大喊大叫删除[/编辑]
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.

Shouting removed[/Edit]


这篇关于ASp.net C#.how将不同用户重定向到不同的页面。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆