The role provider changed several versions ago (4.3.3 if I recall correctly). The UserInfo object now contains a Roles property which would appear to be able to provide an array of strings containing the role names to which the user belongs. In most (but not all situations) the Roles property is properly hydrated for the currently logged in user (Me.UserInfo). The UserInfo object also provides an IsInRole(ByVal rolename As String) function which should return true if the user is a member of the provided role name.
Unfortunately, the Roles property is NOT reliably hydrated for the currently logged in user returning an empty array and causing IsInRole to always return false. The Roles property is NEVER hydrated when the UserInfo object has been obtained for a particular user - for example using code such as:
Dim ui As DotNetNuke.Entities.Users.UserInfo=DotNetNuke.Entities.Users.UserController.GetUserByName(Me.PortalId, "someusername")
I usually use the following code for obtaining a string array of role names to which a particular user belongs:
Dim ui As DotNetNuke.Entities.Users.UserInfo=DotNetNuke.Entities.Users.UserController.GetUserByName(Me.PortalId, "someusername")
Dim rc As New DotNetNuke.Entities.Roles.RoleController()
If Not ui Is Nothing Then
Dim Roles () As String = rc.GetRolesByUser(ui.UserId, Me.PortalId)
'Do something with the Roles array . . .
End If
If you want to use the UserInfo.IsInRole(ByVal rolename As String) function, you can manually hydrate the Roles property first:
Dim ui As DotNetNuke.Entities.Users.UserInfo=DotNetNuke.Entities.Users.UserController.GetUserByName(Me.PortalId, "someusername")
Dim rc As New DotNetNuke.Entities.Roles.RoleController()
If Not ui Is Nothing Then
ui.Roles= rc.GetRolesByUser(ui.UserId, Me.PortalId)
If ui.IsInRole("ContentEditors") Then
'The specified user is a member of the ContentEditors role
End If
End If