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!
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