Toolbox filtering: Register the IToolboxFilter in the ObjectFactory

To apply the filtering that you created when implementing IToolboxFilter interface, you need to replace the default filter. Sitefinity's default IToolboxFilter implementation is the DefaultToolboxFilter class. This class reports as visible only sections and items that are enabled. In addition, it also implements the logic for displaying backend section and items when editing a backend page.

You can replace the default filter by registering a custom instance in the ObjectFactory.
Perform the following:

  1. In Visual Studio, open your project's Global.asax file.

    NOTE: If you do not have a Global.asax file, create a new Global.asax file and add it to your project. In the context menu of your project, click Add » New Item… » Visual C# » Web » Global Application Class.

  2. Add the following code inside the Application_Start method and hook to the ObjectFactory_Initialized event:

      As a result, the DefaultToolboxFilter is replaced with your custom RoleToolboxFilter.

To test your newly registered filter that allows only users in the Administrator role to use the News widget, perform the following:

  1. Navigate to Administration » Settings » Advanced » Toolboxes » Toolboxes » PageControls » Sections » ContentToolboxSection » Tools » NewsView
  2. In the Tags field enter role:Administrators
  3. Click Save changes.

 

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?