在数据库中建了User表 和 UserGroupID表(记录用户对应的角色分别为管理员ID为1、分析员ID为2、登记员ID为3),登录时从数据库中读取用户信息,用session记录下用户的角色ID,进行判断后,进入一个主页面(里面有三个Panel面板,装着菜单导航项),在主页面中接受登录时传来的角色ID,然后判断不同的用户角色,得到不同的菜单导航项,怎么实现?请高手们给些提示,最好是代码,小弟不胜感激

解决方案 »

  1.   

    今天是不是北大青鸟毕业日啊,csdn好像被攻占了。
      

  2.   

    登录的时候传递一个Session["Rloe"];如果是管理员,则Session["Role"]="1",依次类推;
    然后主页面的Page_Load事件中进行判断,if(Session["Role"].toString()=="1")
    {
    this.Panel1.Visible = true;
    this.Panel2.Visible = false;
    this.Panel3.Visible = false;
    }
    其它同理可得。。
      

  3.   

     根据角色查询相关模块,绑定到treeview
    Panel1.Controls.Add(动态添加);
      

  4.   

    既然你是三个panel,应该就是针对三个不同的用户而创造的3个,所以只要隐藏其中两个,显示一个就可以了,楼上做法挺专业。。
      

  5.   

    登录界面:
    if(管理员)
    {
    Session["Role"]="1";
    //跳转语句
    }
    else if 
    {
    Session["Role"]="2";
    //跳转语句
    }
    else
    {
    Session["Role"]="3";
    //跳转语句
    }
    这是一个全局的变量,有效范围是一直到当前浏览器关闭,页就相当于已经存在了一个可用的变量,存储的是你的角色名,直接使用。
    protected void Page_Load(object sender, EventArgs e)
    {
    if(Session["Role"].toString()=="1")
    {
    this.Panel1.Visible = true;
    this.Panel2.Visible = false;
    this.Panel3.Visible = false;
    }
    else if(Session["Role"].toString()=="2")
    {
    this.Panel1.Visible = false;
    this.Panel2.Visible = true;
    this.Panel3.Visible = false;
    }
    else(Session["Role"].toString()=="3")
    {
    this.Panel1.Visible = false;
    this.Panel2.Visible = false;
    this.Panel3.Visible = true;
    }
    }
      

  6.   

    代码写的潦草了,Session["Role"]=你从数据库读出的角色ID ,从数据库读取你应该了解了吧?
      

  7.   

      protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] != null)
            {
                //得到用户信息
                UserInfo user = (UserInfo)Session["user"];
                DisplayUserMenu(user);
            }
        }    protected void DisplayUserMenu(UserInfo user)
        {
            TVSysFun.Nodes.Clear();
            IList<SysFun> parentSysFun = SysFunManager.GetAllParentNodeInfoByUserId(user);
            foreach (SysFun sfParent in parentSysFun)
            {
                string nodeId = sfParent.NodeId.ToString();//第一层节点id
                string displayName = sfParent.DisplayName;//第一层节点显示名称            TreeNode fatherNode = this.CreatTreeNode(displayName, nodeId, "", "Images/tree/folder_closed.gif");//根据节点信息,创建第一层节点            CreateChildTree(nodeId, user, fatherNode);//创建子节点            TVSysFun.Nodes.Add(fatherNode);//将第一层节点加入到用户权限TreeView中
            }    }    //创建第二层节点
        private void CreateChildTree(string nodeId, UserInfo user, TreeNode fatherNode)
        {
            IList<SysFun> childSysFun = SysFunManager.GetSysFunByParentNodeIdAndUserId(user,  int.Parse(nodeId));//获得父节点为nodeId的所有子节点        foreach (SysFun sfChild in childSysFun)
            {
                string childNodeId = sfChild.NodeId.ToString();//第二层节点id
                string childDisplayName = sfChild.DisplayName;//第二层节点名称
                string nodeURL = ResolveUrl(sfChild.NodeURL.Trim());//将路径转换为在客户端可用的URL            TreeNode childNode = this.CreatTreeNode(childDisplayName, childNodeId, nodeURL, "Images/tree/folder_open.gif");//根据节点信息,创建第二层节点
                AddTree(fatherNode, childNode);//将子节点加入到父节点中
            }
        }
        /// <summary>
        /// 创建一个树节点,返回一个树节点对象,参数内容是:
        /// 节点名称,节点ID,链接地址,正常图标,展开后的图标
        /// </summary>
        private TreeNode CreatTreeNode(string strText, string strId, string strUrl, string strImg)
        {
            TreeNode newNode = new TreeNode();
            newNode.Text = strText;
            newNode.Value = strId;
            newNode.NavigateUrl = strUrl;
            newNode.ImageUrl = strImg;
            return newNode;
        }    /// <summary>
        /// 把子节点添加到父节点当中
        /// </summary>
        private void AddTree(TreeNode FatherNode, TreeNode ChildNode)
        {
            FatherNode.ChildNodes.Add(ChildNode);
        }
    就这个我刚做过的,试试吧。
      

  8.   

    無需代碼,用loginView控件即可實現!