Umbraco Role Based Protection - Getting A Content Page's Membership Roles & Getting Membership Roles of a User

If you have set up Public Access roles for a content page using the Umbraco CMS and you need to reach the roles of this content page in the code behind, then this is how you can do it;
var roles = umbraco.cms.businesslogic.web.Access.GetAccessingMembershipRoles(content.Id,content.Path);
If you need to get all roles, then this is how you can get it;
var allRoles = ApplicationContext.Current.Services.MemberService.GetAllRoles();
In addition to this, we can get the member roles as shown below;
var memberRoles = System.Web.Security.Roles.GetRolesForUser(member.Username).ToList();

Happy coding.


Popular posts from this blog

Fix for "Websites cannot be started unless both the Windows Activation Service (WAS) and the World Wide Web Publishing Service (W3SVC) are running, Both services are currently stopped"

Solution for "Can not obtain Oracle client information from registry"

How to specify proxy credentials in web.config