Roles Demo
With skmMenu, MenuItems can be assigned a set of roles. By giving a MenuItem a set of roles, it indicates
that only users who belong to at least one of the MenuItem roles can view that MenuItem.
Additionally, the skmMenu has a UserRoles property, which indicates the role(s) the current user viewing
skmMenu belongs to. This dictates what menu items he can see.
In the demo below, you can toggle what roles you are given. The menu items titled "Dev Only" are only viewable
with users who have the Dev role, and so on... Be sure to check out the RoleXML.xml file
to see the XML markup used to give roles to a menu item.
For more information on roles with skmMenu, refer to the remarks in the UserRoles
property documentation...
Source Code
HTML Portion
<form id="Form2" method="post" runat="server">
<cc1:menu id="Menu2" runat="server" BackColor="#FFE0C0" ItemSpacing="0" Font-Names="Arial"
Font-Size="X-Small"></cc1:menu>
<p>
<b>Your Roles</b>
<asp:CheckBoxList id="Checkboxlist1" runat="server">
<asp:ListItem Value="Admin">Admin</asp:ListItem>
<asp:ListItem Selected="True" Value="Dev">Dev</asp:ListItem>
<asp:ListItem Selected="True" Value="Test">Test</asp:ListItem>
</asp:CheckBoxList></p>
<asp:Button Runat="server" Text="Change Roles" id="Button2"></asp:Button></form>
Code-Behind Class
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
Menu1.UserRoles.Add("dev");
Menu1.UserRoles.Add("test");
Menu1.DataSource = Server.MapPath("RoleXML.xml");
Menu1.DataBind();
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
// clear out roles
Menu1.UserRoles.Clear();
// assign roles
if (this.chkRoleList.Items[0].Selected)
Menu1.UserRoles.Add("admin");
if (this.chkRoleList.Items[1].Selected)
Menu1.UserRoles.Add("dev");
if (this.chkRoleList.Items[2].Selected)
Menu1.UserRoles.Add("test");
// rebind menu
Menu1.DataSource = Server.MapPath("RoleXML.xml");
Menu1.DataBind();
}
|