Try our conversational search powered by Generative AI!

Programmatically check if request validate Visitor Group requirments


Hello guys,

I have some geolocation based Visitor Groups and a content area withe several blocks. How can i know if each of the blocks meets the requirement of the Visitor Group set in episerver?

So far I looped through AllowedRoles, i get the visitor group, i get the user from context. Now, how can i check that the user is able or not to see the block? 

foreach (var content in contentarea.Items)
                if (content.AllowedRoles != null)
                    var match = false;
                    foreach (var item in content.AllowedRoles)
                        var visitorGroupRepo = ServiceLocator.Current.GetInstance();
                        var vg = new Guid(item);
                        var visitorGroup = visitorGroupRepo.Load(vg);
                        var user = HttpContext.User;
                        // how what?
Edited, Oct 19, 2018 11:47

Hi Alex,

Rather than try to evaluate it yourself, I suspect just using contentarea.FilteredItems would do what you need. FilteredItems applies the personalisation rules as well as checking permissions and published status of the content in the contentarea so will return only items which the current user should be able to see.

Oct 19, 2018 16:03

Hello Paul,

Ideed, FilteredItems did the trick in my case. Thank you so much!

Oct 22, 2018 7:41

Hey Alex!

Don't forget to mark the correct answer. Helps out future visitors. smile

Oct 22, 2018 8:51
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.