如何隐藏特定用户的菜单?

时间:2012-02-13 13:11:10

标签: asp.net c#-4.0

如何根据用户的登录类型隐藏特定用户的特定菜单?我有一个母版页。

  1. 我有四个主要用户
  2. 每位用户在登录时都会重定向自己的页面。
  3. 我想要的是根据每个用户的登录类型隐藏一些菜单。

    1. 如果管理员只登录他所需的菜单应该向他显示,这个菜单不应该对其他用户可用。
    2. 我的登录代码就像这样

      protected void btnLogin_Click(object sender, EventArgs e)
          {
              //Response.Redirect("~//Administration/DashBoard.aspx");
              SqlConnection con = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DebitCareBankApp;Data Source=SSDEV7-HP\\SQLEXPRESS");
              string cmdStr = "select LoginType from Login where UserName='" + TxtUserName.Text + "' AND Password = '" + TxtPassword.Text + "'";
              SqlCommand cmd = new SqlCommand(cmdStr, con);
              con.Open();
              Object TypeUser = cmd.ExecuteScalar();
              con.Close();
              //int switchcase = int.Parse(TypeUser);
              if (TypeUser != null)
              {
                  LblError.Visible = false;
                  LblError.Text = "";
                  if (TypeUser.ToString() == "Manager")
                  {
      
                      Response.Redirect("~//Administration/Manager/WorkManagement.aspx");
                  }
                  else if (TypeUser.ToString() == "HR")
                  {
                                   Response.Redirect("~//Administration/Hr/CalculateAndGeneratePayslips.aspx");
                  }
                  else if (TypeUser.ToString() == "Employee")
                  {
                      Response.Redirect("~//Administration/CallingAgent/TodaysWork.aspx");
                  }
              }
              else
              {
                  LblError.Visible = true;
                  LblError.Text = "Invalid Credentials Entered, Try again";
              }
          }
      

1 个答案:

答案 0 :(得分:0)

我过去曾为此目的使用过数据库表。我曾经在数据库中存储菜单和角色,并根据记录的用户询问它们,然后创建菜单。

它通常有效,但如果你能告诉我你创建菜单的方式,我可以详细说明我的答案。请添加为评论。

此致