2012-02-13 26 views
1

嗨如何根據thier登錄類型來隱藏特定用戶的特定菜單...我有一個母版頁......如何隱藏特定用戶的菜單?

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

我想是我想隱藏的所有用戶一些菜單基於thier登錄類型

1)if Manager logins only his required menu should be shown to him,this menu shouldn't be avaliable to other users 

我登錄的代碼是這樣的

  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"; 
     } 
    } 
+0

你是如何建立你的菜單?您是使用UserControl來做到這一點,還是在每個頁面中手動建立菜單? – 2012-02-13 13:18:50

回答

0

我使用的數據庫表爲此,在過去。我曾經在數據庫中存儲菜單和角色,並根據記錄的用戶來詢問它們,然後創建菜單。

它通常工作,但如果你能告訴我你創建菜單的方式,我可以詳細說明我的答案。請添加爲評論。

Regards

+0

在我的數據庫中,我只有角色類型.....沒有菜單欄...我但我assiginning id到我的菜單控件 – SoftwareNerd 2012-02-13 13:34:45

+0

如果你也可以有一個菜單表和角色菜單表中的一對多關係,你可以使用菜單表根據用戶生成菜單。 – AnarchistGeek 2012-02-13 13:40:44

+0

,我建議你將這些路徑存儲在角色表中。如果你添加另一列到你的角色表中,比如重定向和存儲重定向,比如〜/ Administration/Manager/WorkManagement.aspx,你的代碼將會更清晰 – AnarchistGeek 2012-02-13 13:44:56

相關問題