chris vdp
chris vdp

Reputation: 2842

Role based navigation in Razor

We are creating a back end admin system and want to allow users in roles such as finance and membership to have access to certain areas. Ideally we would like to show only areas that you have access to in the navigation.

Using umbraco 4.7+ and razor. We are using the Microsoft role provider.

I was wondering if anyone knows how I could access the currently logged in users role?

Upvotes: 0

Views: 1733

Answers (1)

Douglas Ludlow
Douglas Ludlow

Reputation: 10942

DynamicNode has two methods that will be your friends here, HasAccess() and IsProtected(). Here's an example of how to filter and show nodes that the user only has access to. Here's another one.

Using those methods you shouldn't need to have to get the roles of the currently logged in user, but that's not hard to do as well. Roles.GetRolesForUser() returns an array of the currently logged in user's roles. For more information, refer to the documentation.

Upvotes: 4

Related Questions