各位大侠,我是菜鸟,小弟有问题问,着急啊。我做了个很小网站,有几个板块,只有登录才能浏览,一下有简单代码,但是不成功,不管是否登录,都不能浏览,大侠帮我看看啊!!谢谢
点击“登录”:
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "Data Source=localhost;Initial Catalog=电影信息交流系统;Integrated Security=True"; try
{
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
if ("会员" == DropDownList1.Text)
{
cmd.CommandText = "select * from 用户信息表 where 注册用户名 = '" + TextBox1.Text + "'and 密码='" + TextBox2.Text + "'";
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
//登陆成功
Session["rename"] = "ok"; /////////////////////////登录成功,设置成ok!!
Response.Redirect("欢迎会员.aspx");
}
else
{
//登陆不成功
Response.Write(" <script>alert('错误!请重新输入用户名或密码!!') </script>");
}
dr.Close();
}
else if ("管理员" == DropDownList1.Text)
{
cmd.CommandText = "select * from 管理员表 where 管理员用户名 = '" + TextBox1.Text + "'and 密码='" + TextBox2.Text + "'";
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
//登陆成功
Response.Redirect("欢迎管理员.aspx");
}
else
{
//登陆不成功
// MessageBox.Show("错误!请重新输入用户名或密码!");
Response.Write(" <script>alert('错误!请重新输入用户名或密码!!') </script>");
}
dr.Close();
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message); } cn.Close();
}
在某个板块:(我希望登录才能浏览)在主页中点击一个hyperlink进入.
protected void Page_Load(object sender, EventArgs e)
{
if (Session["rename"] == null||Session["rename"].ToString()!="ok") //////////////判断!
{
Response.Redirect("loginFail.aspx");
}
else
{
Response.Redirect("影视档案.aspx");
}
}
点击“登录”:
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "Data Source=localhost;Initial Catalog=电影信息交流系统;Integrated Security=True"; try
{
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
if ("会员" == DropDownList1.Text)
{
cmd.CommandText = "select * from 用户信息表 where 注册用户名 = '" + TextBox1.Text + "'and 密码='" + TextBox2.Text + "'";
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
//登陆成功
Session["rename"] = "ok"; /////////////////////////登录成功,设置成ok!!
Response.Redirect("欢迎会员.aspx");
}
else
{
//登陆不成功
Response.Write(" <script>alert('错误!请重新输入用户名或密码!!') </script>");
}
dr.Close();
}
else if ("管理员" == DropDownList1.Text)
{
cmd.CommandText = "select * from 管理员表 where 管理员用户名 = '" + TextBox1.Text + "'and 密码='" + TextBox2.Text + "'";
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
//登陆成功
Response.Redirect("欢迎管理员.aspx");
}
else
{
//登陆不成功
// MessageBox.Show("错误!请重新输入用户名或密码!");
Response.Write(" <script>alert('错误!请重新输入用户名或密码!!') </script>");
}
dr.Close();
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message); } cn.Close();
}
在某个板块:(我希望登录才能浏览)在主页中点击一个hyperlink进入.
protected void Page_Load(object sender, EventArgs e)
{
if (Session["rename"] == null||Session["rename"].ToString()!="ok") //////////////判断!
{
Response.Redirect("loginFail.aspx");
}
else
{
Response.Redirect("影视档案.aspx");
}
}
解决方案 »
- 如何针对这种需求设计类结构?
- 在PANEL中如何获得键盘事件?
- 给客户开发过网站并开过发票的请进
- 一个关于Session的问题,到底有几种原因会导致Session过期?
- DataGridViewAutoFilterColumnHeaderCell里筛选的ListBox点开后会留下一条白色的痕迹,有图
- datagridview数据显示一段时间就不显示了
- 如何将Excel中的数据导到Access的数据库里面来
- 如何把Unix下的时间戳(timestamp)转化为DateTime类型??
- 怎么判断程序所在的当前路径
- 如何得到本地计算机的域名或组名???急
- 怎么在VS05中添加外部的控件?
- C#讀取INI問題
第一次来看asp.net内容
不错