Search code examples
umbracoumbraco7user-roles

Get roles of page with role based protection


What's the current alternative to umbraco.cms.businesslogic.web.Access.GetAccessingMembershipRoles? Because umbraco 7.6 highlights it as obsolete and tells to use IPublicAccessService

I was unable to find out how to use it though, all I got to was

IContent content = GetById(id);
Attempt<PublicAccessEntry> access = _publicAccessService.IsProtected(content);

which doesn't have any information about the current page roles.


Solution

  • This is how you do it;

    IContent content = GetById(id);
    var publicAccessService = ApplicationContext.Current.Services.PublicAccessService;
    var entryForContent = publicAccessService.GetEntryForContent(content);
    

    You will see that entryForContent result has got Rules and this is what you need. See details below;

    enter image description here

    enter image description here