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

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

Solution for the fault: "System.Diagnostics.Process.Start is not working on IIS, but working on ASP.NET Development Server"

Getting Umbraco Content - IPublishedContent vs IContent vs Node vs Document