我想让我的三个角色进入不同的页面代码如下:
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>");
    }
}

解决方案 »

  1.   

    跳错了都跳到 'manageIndex.aspx '页面了
      

  2.   

    先把角色取出来,不要直接用read.Read()做条件
    然后就是if...else 或switch...case 
      

  3.   

    用这样写连接数据库吧。把数据全部加载到DataSet里面 在取出来 判断,不用SqlDataReaderDataSet ds = new DataSet();
                //定义连接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();
                }
      

  4.   

    用户信息设置角色字段,配置角色访问权限
    获取角色跳转到相关页面
    或使用forms 验证
      

  5.   

    LZ代码登录后的逻辑明显有问题:if(read.Read()) 
    {
    }
    这里只能判断客户是否能登录
    但你还要判断客户时什么类型的,再决定跳转你这里根本没有判断客户是什么类型
    所以只要客户登录成功了,就执行第一个 判断里的JS:打开第一个manageIndex.aspx
    你需要在把判断放在read.read()后的块里,后面2个if(read.Read()){}可以删掉,根本不会执行另:LZ这里跳转请用:window.location.href="manageIndex.aspx";
    window.open("manageIndex.aspx"),是在当前窗口代开