Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Latest DNN - What happened to Roles? System.Web.Security.Roles.GetRolesForUser.Latest DNN - What happened to Roles? System.Web.Security.Roles.GetRolesForUser.
Previous
 
Next
New Post
1/13/2007 7:46 PM
 
Hello,

In previous versions of DNN with roleprovider support, I was able to use:
System.Web.Security.Roles.GetRolesForUser (USER_NAME);

to get a string array of roles for a particular user.

It appears as I am not able to use that method anymore. First of all the default web.config has no rolemanager set up (why not?). I perused the documentation a little bit and got confused fairly quickly. I tried some code that was mimicked from the admin screens, to no avail.

How are the roles set up as default in the latest version of DNN and how can I get the roles for the logged in user?

Thanks,
ELmO
 
New Post
5/7/2007 1:49 PM
 

I have hit this issue as well - have you had any luck resolving?

My previous version had a roleManager defined - DNNSQLRoleProvider, so I have restored this in my 4.5.1 install - but still have the issue of GetRolesForUser not returning anything.

 
New Post
5/7/2007 4:57 PM
 

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


Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Latest DNN - What happened to Roles? System.Web.Security.Roles.GetRolesForUser.Latest DNN - What happened to Roles? System.Web.Security.Roles.GetRolesForUser.


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out