Get visitor groups for the current visitor



Is there a way to get in code all visitor groups that the current visitor may be part of while they are browsing the site? I found only how to get all visitor groups - using visitorGroupRepository.List().

Thank you,


Feb 15, 2018 12:27

I think you can try something like this:

var visitorGroupRepository = ServiceLocator.Current.GetInstance<IVisitorGroupRepository>();
                var visitorGroupRoleRepository = ServiceLocator.Current.GetInstance<IVisitorGroupRoleRepository>();

                var helper = new VisitorGroupHelper(visitorGroupRoleRepository);
                var groups = visitorGroupRepository.List();
                foreach (var visitorGroup in groups)
                        // add to your collection
Feb 16, 2018 14:08

Hello! Thanks for your answer!

For me it worked the code below, in case there is someone who needs this.

private List<string> GetVisitorGroupIdsByCurrentUser(HttpContextBase httpContext)
var visitorGroupId = new List<string>();
var user = httpContext.User;
var visitorGroups = _visitorGroupRepository.List();
foreach (var visitorGroup in visitorGroups)
if (_visitorGroupRoleRepository.TryGetRole(visitorGroup.Name, out var virtualRoleObject))
if (virtualRoleObject.IsMatch(user, httpContext))

return visitorGroupId;

Edited, Feb 19, 2018 9:10
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.