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:




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: