是这样的,小弟初学.net,找了段源码学习研究。可这刚到登录页就卡住了。在login页的cs代码里找来找去都没找到与数据库连接,验证用户名和密码的地方。小弟不才,请各位指点。 void UserLogin()
    {
        bool p = new LoginT().TloginCheck(txtUserName.Text, txtpassword.Text);
        if (p)
        {
            DataSet ds = new DataSet();
            ds = new LoginT().TloginSession(txtUserName.Text, txtpassword.Text);
            System.Web.HttpContext.Current.Session.Timeout = 10000;//将session时间设为10000
            Session["u"] = "u";//提供session对象
            Session["UserId"] = txtUserName.Text;
            Session["UserName"] = ds.Tables[0].Rows[0][1].ToString();
            Session["Psw"] = ds.Tables[0].Rows[0][2].ToString();
            Session["Rankid"] = ds.Tables[0].Rows[0][4].ToString();
            Session["RankName"] = ds.Tables[0].Rows[0][5].ToString();
            if (ds.Tables[0].Rows[0][4].ToString().Trim() == "1")//判断登录权限
            {
                Response.Redirect("sys_admin.aspx");//登录到系统管理员界面
                return;
            }
             if (ds.Tables[0].Rows[0][4].ToString().Trim() == "2")
            {
                Response.Redirect("sys_leader.aspx");//登录到校领导界面
                return;
            }
            if (ds.Tables[0].Rows[0][4].ToString().Trim() == "3")
            {
                Response.Redirect("sys_warehourse.aspx");//登录到仓管员界面
                return;
            }            Response.Redirect("sys_worker.aspx");//登录到招生工作人员界面        }
        else
        {
            Utility.CsHelper.ExecJS("帐号或密码错误!", this.Page);
        }
        Clear();    
    
    
    
    }

解决方案 »

  1.   

    这不是验证用户名和密码的吗? bool p = new LoginT().TloginCheck(txtUserName.Text, txtpassword.Text); 
     if (p) 
    ...
      

  2.   

    你的数据库连接应该写在TloginSession()方法里面
      

  3.   

      Session["UserId"] = txtUserName.Text; 
                Session["UserName"] = ds.Tables[0].Rows[0][1].ToString(); 这个难道不是?
      

  4.   

    bool p = new LoginT().TloginCheck(txtUserName.Text, txtpassword.Text); 查看LoginT类中的TloginCheck方法
      

  5.   

    LoginT().TloginCheck(txtUserName.Text, txtpassword.Text); 
    楼主不知道封装吗?上行中引用的LoginT这个类型中封装了登录验证逻辑,要了解详细,找到这个类的定义
      

  6.   

    bool p = new LoginT().TloginCheck(txtUserName.Text, txtpassword.Text);你这个肯定是调用别人的公共类,连接字符串都在那个公共类里。
      if (ds.Tables[0].Rows[0][4].ToString().Trim() == "1")//判断登录权限 
                { 
                    Response.Redirect("sys_admin.aspx");//登录到系统管理员界面 
                    return; 
                } 
    还有就是没必要加Return,如果if条件成功,则直接跳转了,何来Return执行。建议你还是认真学点基础知识吧。
      

  7.   

    人家是写在 这个 函数 里面 的:
    ds = new LoginT().TloginSession(txtUserName.Text, txtpassword.Text); 中的  TloginSession(txtUserName.Text, txtpassword.Text) 函数了 呀,并将 判断结果 返回
      

  8.   

    先谢谢楼上各位!谢谢各位的热心!这一说明白多了。刚找到了 类loginT.cs ,打开里面有 TloginCheck 和 TloginSession ,但还是没看懂,能进一步说说么?代码如下:public LoginT()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    }
        public bool TloginCheck(string UserId, string Passwd)
        {
            SqlParameter[] p = new SqlParameter[3];
            p[0] = new SqlParameter("@Userid", SqlDbType.Char, 10);
            p[0].Direction = ParameterDirection.Input;
            p[0].Value = UserId;
            p[1] = new SqlParameter("@Password", SqlDbType.VarChar, 50);
            p[1].Direction = ParameterDirection.Input;
            p[1].Value = Passwd;
            p[2] = new SqlParameter("@R", SqlDbType.Int);
            p[2].Direction = ParameterDirection.ReturnValue;
            DbHelper.RunProcedure("LoginCheck", p);
            int temp = Convert.ToInt32(p[2].Value);
            if (temp == 0)
            {
                return false;
            }
            else
            {
                return true;
            }    }
        public DataSet TloginSession(string UserId, string Passwd)
        {
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@Userid", SqlDbType.Char, 10);
            p[0].Direction = ParameterDirection.Input;
            p[0].Value = UserId;
            p[1] = new SqlParameter("@Password", SqlDbType.VarChar, 50);
            p[1].Direction = ParameterDirection.Input;
            p[1].Value = Passwd;        return DbHelper.RunProcedure("LoginSession", p);    }
      

  9.   

    .........这,你还是看msdn吧这些都是最简单的数据库连接问题
      

  10.   

    return DbHelper.RunProcedure("LoginSession", p); ,连接字符串在这,也就是在DbHelper类中,我估计你找的这个例子,是用三层架构做的,建议你还是学习哈数据库连接再做这个好了
      

  11.   

    bool p = new LoginT().TloginCheck(txtUserName.Text, txtpassword.Text); 
    这个就是判断用户名密码的函数了。