1
votes

How can I hide a particular menu for a particular user based on their login type? I have a master page.

  1. I have four Main users
  2. Each user is redirected his own page on login.

What I want is to hide some menus for every user on based on their login type.

  1. if Manager logs in only his required menu should be shown to him, this menu shouldn't be available to other users.

my login code goes like this

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
How are you building your menu? Are you using a UserControl to do that, or in each page you build the menu manually? - Vinicius Ottoni

1 Answers

0
votes

I used database tables for this purpose in the past. I used to store menus and roles in database and interrogating them based on the logged user then create the menu.

It generally works, but if you could tell me the way you create menus, I can elaborate my answer. please add as comment.

Regards