Hezron Naresh Hezron Naresh - 1 year ago 186
ASP.NET (C#) Question

Get All User Roles in DNN

public DnnRole GetDnnRoleByName(int portalId, string dnnRoleName)
DnnRole role = null;
RoleController rc = new RoleController();
RoleInfo dnnRole = rc.GetRoleByName(portalId, dnnRoleName);

if (dnnRole != null)
role = new DnnRole();
role.Id = dnnRole.RoleID;
role.RoleName = dnnRole.RoleName;
role.Description = dnnRole.Description;


Above is my code to get the Roles for many purposes and this DNN predefined method. But when I try to get the Role ID for All Users(DNN default role) it gives a error. Because this role does not has portal Id. Can you please advice is there any way to get this with out hard code the role id.

Answer Source

Here you go...

RoleController RoleController = new RoleController();
IList<RoleInfo> roleInfoArr = RoleController.GetRoles(PortalId);

foreach (RoleInfo roleInfo in roleInfoArr)
    if (roleInfo.RoleName == "All Users")

But the ID for All Users is always -1 for every Portal.

For Superusers it's -2

For Unauthenticated Users it's -3

Note that the Administrator roleId IS different per portal

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download