我有三个用户,三个用户数据库用了一个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(); }
}
这是我就一个用户的时候弄的,
我也试着做了三个用户的判定,但是老提示出错,搞了几天,最后还得麻烦各位大侠帮我把代码弄出来
在此谢谢大家了
程序代码:
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(); }
}
这是我就一个用户的时候弄的,
我也试着做了三个用户的判定,但是老提示出错,搞了几天,最后还得麻烦各位大侠帮我把代码弄出来
在此谢谢大家了
Response.Redirect("Loginsuccess.aspx"); 你连续写两个跳转,这个地方当然都会跳到Loginsuccess页面。
{
Response.Redirect("1.aspx");
}
i(usertype=2)
{
Response.Redirect("2.aspx");
}
,
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();
}
}