Modify permissions of dynamic content items using the Fluent API

You can use the fluent API to modify the permissions of dynamic content items. The entry point for managing a dynamic content item’s permissions is the ManagePermissions() extension method on DynamicContent, which is available in the Telerik.Sitefinity.Model namespace.

In the following example the permissions of a specific Article dynamic content item, are being modified by allowing the Designers role to view it:

The example above implicitly breaks the permission inheritance for the specific item. This is done by copying the permissions of the parent item and assigning those copies as the item’s own Permissions collection. Afterwards, the new permission objects are modified so that the View actions is allowed for the Designers role.

In combination with dynamic content events, you can achieve more complex scenarios - for example, defaulting the permissions of all items of specific type to a desired state, as in the following example that is taken from a Global.asax.cs file.

As you can see in the example above, the creating event is used, which is raised just before the transaction, in which an item has been created is committed. This is why no SaveChanges call is required for the changes to take effect.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?