London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Loading...
Area: Optimizely CMS
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Introduction

It is possible to control which groups are allowed to view and select a certain component. This is done by defining the AllowedRoles property for a component definition. It is also possible to hide a component completely by setting the Allowed Roles property to “none”. Setting it to null/String. Empty simply means that no access check should be done.

Example

The example below shows how to hide or show a certain component depending on a global setting.

C#
[Component]
    public class FileManagementComponent : ComponentDefinitionBase
    {
        public FileManagementComponent()
            : base("epi-cms.component.FileManagement")
        {
            Categories = new string[]{"cms"};
            LanguagePath = "/episerver/cms/components/filemanagement";
            SortOrder = 200;
            PlugInAreas = new string[] { PlugInArea.DefaultAssetsGroup };

            if (!EPiServer.Configuration.Settings.Instance.UseLegacyFileManagerMode)
            {
                AllowedRoles.Clear();
                AllowedRoles.Add("none");
            }
        }
    }
}

Last updated: Feb 23, 2015