November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
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) { if(helper.IsPrincipalInGroup(User,visitorGroup.Name)) // add to your collection }
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)) { visitorGroupId.Add(visitorGroup.Id.ToString()); } } } return visitorGroupId; }
Hello!
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,
Simona