Try our conversational search powered by Generative AI!

smithsson68@gmail.com
Apr 11, 2011
  7725
(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
The A/A Test: What You Need to Know

Sure, we all know what an A/B test can do. But what is an A/A test? How is it different? With an A/B test, we know that we can take a webpage (our...

Lindsey Rogers | Apr 15, 2024

.Net Core Timezone ID's Windows vs Linux

Hey all, First post here and I would like to talk about Timezone ID's and How Windows and Linux systems use different IDs. We currently run a .NET...

sheider | Apr 15, 2024

What's new in Language Manager 5.3.0

In Language Manager (LM) version 5.2.0, we added an option in appsettings.json called TranslateOrCopyContentAreaChildrenBlockForTypes . It does...

Quoc Anh Nguyen | Apr 15, 2024

Optimizely Search & Navigation: Boosting in Unified Search

In the Optimizely Search & Navigation admin view, administrators can set a certain weight of different properties (title, content, summary, or...

Tung Tran | Apr 15, 2024