November Happy Hour will be moved to Thursday December 5th.

smithsson68@gmail.com
Apr 11, 2011
  7953
(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 SaaS CMS + Coveo Search Page

Short on time but need a listing feature with filters, pagination, and sorting? Create a fully functional Coveo-powered search page driven by data...

Damian Smutek | Nov 21, 2024 | Syndicated blog

Optimizely SaaS CMS DAM Picker (Interim)

Simplify your Optimizely SaaS CMS workflow with the Interim DAM Picker Chrome extension. Seamlessly integrate your DAM system, streamlining asset...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Optimizely CMS Roadmap

Explore Optimizely CMS's latest roadmap, packed with developer-focused updates. From SaaS speed to Visual Builder enhancements, developer tooling...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Set Default Culture in Optimizely CMS 12

Take control over culture-specific operations like date and time formatting.

Tomas Hensrud Gulla | Nov 15, 2024 | Syndicated blog

I'm running Optimizely CMS on .NET 9!

It works 🎉

Tomas Hensrud Gulla | Nov 12, 2024 | Syndicated blog

Recraft's image generation with AI-Assistant for Optimizely

Recraft V3 model is outperforming all other models in the image generation space and we are happy to share: Recraft's new model is now available fo...

Luc Gosso (MVP) | Nov 8, 2024 | Syndicated blog