Try our conversational search powered by Generative AI!

smithsson68@gmail.com
Apr 11, 2011
  7729
(1 votes)

Checking if a request matches a Visitor Group from code

You may wish to check that the current Http request matches an EPiServer Visitor Group from code, such as from a page or control template.

Method #1

using EPiServer.Personalization.VisitorGroups;
var match = EPiServer.
             Security.
              PrincipalInfo.
               CurrentPrincipal.
                IsInRole("roleName", SecurityEntityType.VisitorGroup);

 

Method #2

using EPiServer.Personalization.VisitorGroups;
var helper = new VisitorGroupHelper();
var match = helper.IsPrincipalInGroup(principal, "roleName");

Both methods require a reference to the EPiServer.ApplicationModules assembly which is part of the EPiServer Framework.

Happy matching!

Apr 11, 2011

Comments

Sandor Voordes
Sandor Voordes Oct 6, 2012 12:54 AM

Hi Paul,

This is exactly what I want but if I simply use the visitor group name where it says roleName it does not seem to work, which makes sense since it wants a visitorgrouprole name and not a visitor group name. However, I can't seem to get the role name from the groupname.

Any ideas?

Sandor

Please login to comment.
Latest blogs
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog