smithsson68@gmail.com
Apr 11, 2011
  7515
(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
Update on .NET 8 support

With .NET 8 now in release candidate stage I want to share an update about our current thinking about .NET 8 support in Optimizely CMS and Customiz...

Magnus Rahl | Oct 3, 2023

Adding Block Specific JavaScript and CSS to the body and head of the page

A common requirement for CMS implementations includes the ability to embed third party content into a website as if it formed part of the website...

Mark Stott | Oct 3, 2023

Performance optimization – the hardcore series – part 1

Hi again every body. New day – new thing to write about. today we will talk about memory allocation, and effect it has on your website performance....

Quan Mai | Oct 3, 2023 | Syndicated blog

IDX21323 - RequireNonce is true, Nonce was null

We have multiple clients configured with Azure Active Directory (Microsoft Entra) for requiring authentication when accessing their website. The...

David Drouin-Prince | Oct 1, 2023 | Syndicated blog