Loading...

Last updated: Oct 27 2016

Area: Episerver CMS Applies to versions: 10 and higher
Other versions:

Hiding or controlling access to a component

This topic describes how to manage access to a component in the Episerver user interface.

How it works

The AllowedRoles property for a component definitions lets you control the groups that are allowed to view and select a certain component. You can hide a component completely by setting the AllowedRoles property to none, or setting it to a null string which prevents an access check.

Example

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

[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");
            }
        }
    }
}

Do you have feedback on this documentation? Send an email to documentation@episerver.com. For development-related questions and discussions, refer to our Forums on https://world.episerver.com/forum/