skmMenu: An ASP.NET Menu Control

Menu.UserRoles Property

Specifies the roles the current user belongs to. When assigning roles to the MenuItems, the user's roles affect what menu items are displayed.

public RoleCollection UserRoles {get;}

Remarks

Each MenuItem in a skmMenu can be assigned a set of roles. A role is a name that implies some level of access. Roles are denoted as strings. Example roles might be: developer, tester, and admin.

To denote a role for a MenuItem, the Roles property can be used programmatically, or the <roles> XML element can be used if the menu data is supplied in an XML file. (For more information on the <roles> XML element and binding menu data via an XML file, consult http://skmmenu.com/menu/Download/XMLStructure.html.

The Menu class's UserRoles property specifies the set of roles the user viewing the page has. This needs to be set programmatically in the first page load (the role information is persisted across postbacks). Typically this role assignment will need to be done by looking up the current user's set of roles in a database or some other ACL store.

After the UserRoles property has been set, you can bind the XML data to skmMenu through a call to DataBind. Only those MenuItems that either (a) have no roles defined or (b) has a role collection that intersects the UserRoles role collection, will be rendered. For a live demo of roles with skmMenu, see http://skmmenu.com/menu/Examples/Roles.aspx.

See Also

Menu Class | skmMenu Namespace