求助啊,亲们

mrzhongke 2011-12-09 09:51:35
有一张表,三个字段,account,password,type。现在做登录页面,页面上只是输入用户名和密码还有一个验证码,根据输入的用户名和密码到表中对比。如果type是A,就跳到A页,是B就跳到B页,是C就跳到C页,我贴一部分代码,麻烦大家帮我把type判断完成。谢谢了。
protected void imgbtnLogin_Click(object sender, ImageClickEventArgs e)
{
string userName = this.TxtUserName.Value;
string password = this.TxtPassword.Value;
if (userName != "" && password != "")
{
DataTable dt = DBHelper.GetDataSet("select * from employs where ACCOUNT='" + userName +
"' and password='" + password + "'");
if (dt.Rows[0][0].ToString() != "0")
{
//把登录用户保存到Session中
Session["user"] = dt.Rows[0]["ACCOUNT"].ToString();
//判断验证码是否符合
if (Session["VerifyChar"].ToString() == this.txtcode.Value)
{
//应该在此处判断type吧?麻烦大家了
{
Response.Redirect("Main.aspx");
}

}
}
else
{
Response.Write("<script>alert('登录失败,请重新登录!');location.href='index.aspx';</script>");
}
}
else
{
Response.Write("<script>alert('请输入用户名和密码!');location.href='index.aspx';</script>");
}
}
...全文
41 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2011-12-09
  • 打赏
  • 举报
回复
imgbtnLogin_Click(object sender, ImageClickEventArgs e)
{
if (Session["VerifyChar"].ToString() != this.txtcode.Value)
{
Response.Write("<script>alert('请输入验证码!');location.href='index.aspx';</script>");
return;
}

string userName = this.TxtUserName.Value;
string password = this.TxtPassword.Value;
if(userName == "" || password == "")
{
Response.Write("<script>alert('请输入用户名和密码!');location.href='index.aspx';</script>");
return;
}

DataTable dt = DBHelper.GetDataSet("select * from employs where ACCOUNT='" + userName + "' and password='" + password + "'");
if(dt.Rows.Count==0)
{
Response.Write("<script>alert('用户名和密码错误!');location.href='index.aspx';</script>");
return;
}

//把登录用户保存到Session中
Session["user"] = dt.Rows[0]["ACCOUNT"].ToString();
if(dt.Rows[0]["type"].ToString()=="B")
Response.Redirect("~/B.aspx);
else if(dt.Rows[0]["type"].ToString()=="C")
Response.Redirect("~/C.aspx);
else
Response.Redirect("~/Main.aspx);
}
soft_lugy 2011-12-09
  • 打赏
  • 举报
回复
switch(type.ToLower())
{
case 'a':
Response.Redirect("a.aspx");
break;
case 'a':
Response.Redirect("a.aspx");
break;
case 'b':
Response.Redirect("b.aspx");
break;
case 'c':
Response.Redirect("c.aspx");
break;
default:
Response.Redirect("default.aspx");
}
z_f_p 2011-12-09
  • 打赏
  • 举报
回复
ls正解!
孟子E章 2011-12-09
  • 打赏
  • 举报
回复
1,为了减少读取数据库的次数,你应该首先判断验证码
2,你应该先判断dt.Rows.Count>0才能进行读取。用户名、密码表示正确
3.
if(dt.Rows[0]["type"].ToString()=="B")
Response.Redirect("B.aspx);
else if(dt.Rows[0]["type"].ToString()=="C")
Response.Redirect("C.aspx);
else
Response.Redirect("~/Default.aspx);

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧