我有三个用户,三个用户数据库用了一个DropDownList 下面是用户名 密码 和验证码  用同一个登录框,然后登录后分别跳转到对应的页面,
程序代码:
protected void Button1_Click1(object sender, EventArgs e)
    {
        string wbbh = this.wbbh.Value.ToString().Trim();
        string userpass = FormsAuthentication.HashPasswordForStoringInConfigFile(this.pass.Value.ToString().Trim(), "MD5");
        string verify = this.VerifyCode.Value.ToString().Trim();        if (verify != Session["verifycode"].ToString())
        {
            
            Response.Write("<script>alert('验证码不正确!');</script>");
            return;
        }
        else
        {
            SqlConnection MyConn = new SqlConnection(ConfigurationManager.AppSettings["conStr"].ToString());
            SqlCommand MyCommand = new SqlCommand();
            MyCommand.Connection = MyConn;
            MyConn.Open();
            MyCommand.CommandText = "select * from wbreg where wbbh='" + wbbh  + "'and apass='" + userpass + "'";
            try
            {
                SqlDataReader MyReader = MyCommand.ExecuteReader();
                if (MyReader.HasRows)
                {
                    while (MyReader.Read())
                    {
                        Session["wbbh"] = wbbh ;
                       
                        string sUrl = "Loginsuccess.aspx?id=" + wbbh ;
                    Response.Redirect(sUrl);
                    
                    Response.Redirect("Loginsuccess.aspx");
                }
                }
                else
                {
                    
                    Response.Write("<script>alert('登陆失败,请检查你的用户名和密码。');</script>");                }
                MyReader.Close();
            }
            catch
            {
                Response.Write("<script>alert('请确定你的用户名或密码是否正确!');</script>");
                
            }
            MyConn.Close();        }
    }
这是我就一个用户的时候弄的,
我也试着做了三个用户的判定,但是老提示出错,搞了几天,最后还得麻烦各位大侠帮我把代码弄出来
在此谢谢大家了 

解决方案 »

  1.   

    Response.Redirect(sUrl); 
                        
    Response.Redirect("Loginsuccess.aspx"); 你连续写两个跳转,这个地方当然都会跳到Loginsuccess页面。
      

  2.   

    加两个判断就就行了?if(usertype=1)
    {
    Response.Redirect("1.aspx"); 
    }
    i(usertype=2)
    {
    Response.Redirect("2.aspx"); 
    }
      

  3.   

    我的登录界面代码上面已经贴出来了,不过那个做的只是一个用户登录的代码,wbbh是用户名,登录后跳转到Loginsuccess.aspx页面,把登录的用户名传过去,在Loginsuccess.aspx上显示这个用户名的资料,我想要的就是这个功能三个用户,分三个数据库wbreg,wlyysreg,lwdwreg,  里面都有一个字段leixing存放三个用户的类型,数据库wbreg中设置用来登录的用户名是wbbh  , wlyysreg,lwdwreg中设置用来登录的用户名是aname
    ,
    Loginsuccess.aspx页面接受传值的代码
            ST_DataBase ST_database = new ST_DataBase();
            SqlConnection myConn = DBClass.GetConnection();
            protected void Page_Load(object sender, EventArgs e)
            {
                           if (!IsPostBack)
                {
                    if (Session["wbbh"].ToString() == "pass")
                    {
                      
                    }//接受传送数据
                    wbbh.Text = Request.QueryString["id"];
                    string ST_strsql = "select * from wbreg where wbbh='" + Session["wbbh"].ToString() + "'";
                    DataTable ST_dt = new DataTable();
                    ST_dt = ST_database.ReadTable(ST_strsql);
                    truename.Text = ST_dt.Rows[0]["truename"].ToString();
                    wbname.Text = ST_dt.Rows[0]["aname"].ToString();
                    Session["aname"] = wbname.Text;
                    //DLBind();
                }
            }