Setting widget permissions

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

The following sample code shows how you can assign a role and permission to a widget:

 

[C#]

 

using CMS.PortalEngine;

using CMS.SiteProvider;

using CMS.CMSHelper;

 

...

 

        string permissionName = "AllowedFor";

        string resourceName = "Widgets";

        string className = null;

        string roleName = "TestRole";

        int siteID = CMSContext.CurrentSiteID;

 

        // Get role, widget and permission object

        RoleInfo ri = RoleInfoProvider.GetRoleInfo(roleName, siteID);

        WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo("AbuseReport");

      PermissionNameInfo pni = PermissionNameInfoProvider.GetPermissionNameInfo(permissionName, resourceName, className);

 

        // If all exist

        if ((ri != null) && (wi != null) && (pni != null))

        {

            // Add role to widget 

            WidgetRoleInfoProvider.AddRoleToWidget(ri.RoleID, wi.WidgetID, pni.PermissionId);

        }

 

Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?api_setting_widget_permissions.htm