如何根据用户的登录类型隐藏特定用户的特定菜单?我有一个母版页。
我想要的是根据每个用户的登录类型隐藏一些菜单。
我的登录代码就像这样
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 :(得分:0)
我过去曾为此目的使用过数据库表。我曾经在数据库中存储菜单和角色,并根据记录的用户询问它们,然后创建菜单。
它通常有效,但如果你能告诉我你创建菜单的方式,我可以详细说明我的答案。请添加为评论。
此致