API to find out if content has visitor groups configured?

Vote:
 

Is there an API or way to understand whether a piece of content is configured with visitor groups ?

I don't care what those groups are or whether an http request would match any of those groups. I just want to find a way of knowing whether content properties are personalised (ie, content areas, or rich text blocks)

#202955
Apr 04, 2019 13:59
Vote:
 

Hi Mark,

You could loop through the properties on the content and check whether each property is of type IPersonalizedRoles and, if so, check whether there are any roles defined using .Roles(). If it's not an IPersonalizedRoles, check if it's a ContentArea and, if so, check if any of its items have the ContentGroup set. Something like this:

var isPersonalised = myContent.Property.Any(p => ((p as IPersonalizedRoles)?.GetRoles().Any() ?? false) || 
    (((p as PropertyContentArea)?.Value as ContentArea)?.Items?.Any(x => !string.IsNullOrEmpty(x.ContentGroup)) ?? false));

Paul

#202963
Apr 04, 2019 15:19
Vote:
 

You can use the Visitor Group Usage Viewer and check the source code ;): https://www.david-tec.com/2017/12/visitor-group-usage-viewer-for-episerver-11/ 

#202969
Edited, Apr 04, 2019 17:00
Vote:
 

To be fair, that's the post that introduced me to the IPersonalizedRoles interface.

#202976
Apr 04, 2019 19:17
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.