我想让我的三个角色进入不同的页面代码如下:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class admin_login : System.Web.UI.Page
{
SQLHelper sqlh;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Random randobj = new Random();//产生随机数
labCode.Text = randobj.Next(1000, 10000).ToString();
}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
string sql = "select * from 管理员 where userName=@userName and pwd=@pwd and jiaose=@jiaose";
SqlParameter[] paras = { new SqlParameter("@userName", SqlDbType.VarChar),
new SqlParameter("@pwd", SqlDbType.VarChar),
new SqlParameter("@jiaose",SqlDbType.VarChar)};
paras[0].Value = txtAdminName.Text.ToString();
paras[1].Value = txtAdminPwd.Text.ToString();
paras[2].Value = DropDownList1.Text.ToString();
sqlh = new SQLHelper();
SqlDataReader read = sqlh.ExecuteReader(sql,paras,CommandType.Text);
if (txtAdminCode.Text.Trim() == labCode.Text.Trim())
{
if (read.Read())
{
DropDownList1.Text = "总管理员";
Session["adminName"] =txtAdminName.Text;
Session["adminPwd"] = txtAdminPwd.Text;
Response.Write("<script language=javascript>window.open('manageIndex.aspx');window.close();</script>");
}
else
{
Response.Write("<script>alert('您输入的用户名或密码错误,请重新输入!');location='javascript:history.go(-1)';</script>");
}
if (read.Read())
{
DropDownList1.Text = "留言管理员";
Session["adminName"] = txtAdminName.Text;
Session["adminPwd"] = txtAdminPwd.Text;
Response.Write("<script language=javascript>window.open('mesManage.aspx');window.close();</script>");
}
else
{
Response.Write("<script>alert('您输入的用户名或密码错误,请重新输入!');location='javascript:history.go(-1)';</script>");
}
if (read.Read())
{
DropDownList1.Text = "新闻管理员";
Session["adminName"] = txtAdminName.Text;
Session["adminPwd"] = txtAdminPwd.Text;
Response.Write("<script language=javascript>window.open('manageIndex2.aspx');window.close();</script>");
}
else
{
Response.Write("<script>alert('您输入的用户名或密码错误,请重新输入!');location='javascript:history.go(-1)';</script>");
}
}
}
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
Response.Write("<script>window.close();location='javascript:history.go(-1)';</script>");
}
}
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class admin_login : System.Web.UI.Page
{
SQLHelper sqlh;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Random randobj = new Random();//产生随机数
labCode.Text = randobj.Next(1000, 10000).ToString();
}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
string sql = "select * from 管理员 where userName=@userName and pwd=@pwd and jiaose=@jiaose";
SqlParameter[] paras = { new SqlParameter("@userName", SqlDbType.VarChar),
new SqlParameter("@pwd", SqlDbType.VarChar),
new SqlParameter("@jiaose",SqlDbType.VarChar)};
paras[0].Value = txtAdminName.Text.ToString();
paras[1].Value = txtAdminPwd.Text.ToString();
paras[2].Value = DropDownList1.Text.ToString();
sqlh = new SQLHelper();
SqlDataReader read = sqlh.ExecuteReader(sql,paras,CommandType.Text);
if (txtAdminCode.Text.Trim() == labCode.Text.Trim())
{
if (read.Read())
{
DropDownList1.Text = "总管理员";
Session["adminName"] =txtAdminName.Text;
Session["adminPwd"] = txtAdminPwd.Text;
Response.Write("<script language=javascript>window.open('manageIndex.aspx');window.close();</script>");
}
else
{
Response.Write("<script>alert('您输入的用户名或密码错误,请重新输入!');location='javascript:history.go(-1)';</script>");
}
if (read.Read())
{
DropDownList1.Text = "留言管理员";
Session["adminName"] = txtAdminName.Text;
Session["adminPwd"] = txtAdminPwd.Text;
Response.Write("<script language=javascript>window.open('mesManage.aspx');window.close();</script>");
}
else
{
Response.Write("<script>alert('您输入的用户名或密码错误,请重新输入!');location='javascript:history.go(-1)';</script>");
}
if (read.Read())
{
DropDownList1.Text = "新闻管理员";
Session["adminName"] = txtAdminName.Text;
Session["adminPwd"] = txtAdminPwd.Text;
Response.Write("<script language=javascript>window.open('manageIndex2.aspx');window.close();</script>");
}
else
{
Response.Write("<script>alert('您输入的用户名或密码错误,请重新输入!');location='javascript:history.go(-1)';</script>");
}
}
}
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
Response.Write("<script>window.close();location='javascript:history.go(-1)';</script>");
}
}
解决方案 »
- 动态产生的table无法设置样式的问题
- 关于登陆人员类别提问
- |zyciis| 如何不让lblGuestValid.ToolTip += " "; 转成HTML就变成:&#13; 怎么搞啊,谢谢
- ASP.net(vb)怎么连接SQL数据库
- dropdownlist控件选择怎么会无效
- 上传到服务器上,一个ImageButton事件不能触发,很郁闷!!在线等
- Attributes.Add 的问题 如何去掉attributes
- 高分求购一个asp.netC#的控件
- 【,简单问题复杂化?????????】.......................
- TreeView居然控制不了字体?
- 做百分比条遇到麻烦了。大侠救命!!!
- 求助:批量添加,修改功能
然后就是if...else 或switch...case
//定义连接SQL Server数据库字符串
string consqlserver = "Data Source=.;Initial Catalog=PRIVILEGE_TEST;User ID=sa;Password=321670";
//定义SQL查询语句
string sql = "select * from Client_Users where User_Name=@userName";
//定义SQL Server连接对象
SqlConnection con = new SqlConnection(consqlserver);
con.Open();
SqlDataAdapter da = new SqlDataAdapter(sql,con);
SqlParameter A = new SqlParameter("@userName", SqlDbType.VarChar);
A.Value = "admin";
da.SelectCommand.Parameters.Add(A);
try
{
da.Fill(ds);
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
finally
{
con.Close();
con.Dispose();
da.Dispose();
}
获取角色跳转到相关页面
或使用forms 验证
{
}
这里只能判断客户是否能登录
但你还要判断客户时什么类型的,再决定跳转你这里根本没有判断客户是什么类型
所以只要客户登录成功了,就执行第一个 判断里的JS:打开第一个manageIndex.aspx
你需要在把判断放在read.read()后的块里,后面2个if(read.Read()){}可以删掉,根本不会执行另:LZ这里跳转请用:window.location.href="manageIndex.aspx";
window.open("manageIndex.aspx"),是在当前窗口代开