是这样的,小弟初学.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();
}
{
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();
}
if (p)
...
Session["UserName"] = ds.Tables[0].Rows[0][1].ToString(); 这个难道不是?
楼主不知道封装吗?上行中引用的LoginT这个类型中封装了登录验证逻辑,要了解详细,找到这个类的定义
if (ds.Tables[0].Rows[0][4].ToString().Trim() == "1")//判断登录权限
{
Response.Redirect("sys_admin.aspx");//登录到系统管理员界面
return;
}
还有就是没必要加Return,如果if条件成功,则直接跳转了,何来Return执行。建议你还是认真学点基础知识吧。
ds = new LoginT().TloginSession(txtUserName.Text, txtpassword.Text); 中的 TloginSession(txtUserName.Text, txtpassword.Text) 函数了 呀,并将 判断结果 返回
{
//
// 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); }
这个就是判断用户名密码的函数了。