我需要让一些 NavigationMenu 项目只对某些用户可见。就我而言,我需要将其中 2 个设置为仅供管理员使用。
我搜索了谷歌,我发现了一个有效的命令:
NavigationMenu.Items.Remove(NavigationMenu.FindItem("这里是我需要删除的菜单名称"));
到这里,一切正常。但是我需要使用哪个命令才能使其再次可用?
请帮我。提前谢谢 ;)
public partial class SiteMaster : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
NavigationMenu.Items.Remove(NavigationMenu.FindItem("Employers"));
if (Matrix.UserLoggedId == Guid.Empty)
{
hlLogin.Visible = true;
lblUsername.Visible = false;
lnkLogout.Visible = false;
}
else
{
// here goes the code to add the menu
hlLogin.Visible = false;
lblUsername.Visible = true;
lnkLogout.Visible = true;
Marin.Employee.DetailsDataTable emp = Matrix.GetEmployeeByUniqueId(Matrix.UserLoggedId);
if (emp.Rows.Count > 0)
{
lblUsername.Text = emp.Rows[0]["Firstname"].ToString();
bool isAdmin =Convert.ToBoolean(emp.Rows[0]["isAdmin"]);
if (isAdmin)
{
//here goes the code to show the menu
}
else
{
NavigationMenu.Items.Remove(NavigationMenu.FindItem("Employers"));
}
}
}
}