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

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0problem with IsInRolesproblem with IsInRoles
Previous
 
Next
New Post
5/15/2007 11:34 AM
 

I seem to not be using the IsInRole function correctly - can anybody tell me what is wrong with the code posted below

as you can see by the highlight i never have a user in the role Quality Manager even though i can look at the user tables

and see that at least one user is -------------------------------

Dim TotalUsers As Integer
                Dim MyUserList As ArrayList
                MyUserList = UserController.GetUsersByProfileProperty(PortalId, "CompanyID", CompanyID.ToString, 0, 99999, TotalUsers)
                For Each UserItem As UserInfo In MyUserList
                    Dim myUser As UserInfo = DotNetNuke.Entities.Users.UserController.GetUser(PortalId, UserItem.UserID, True)

                    If myUser.IsInRole("Quality Manager") = True Then
                        Response.Write("<br>got here" & myUser.DisplayName)
                      With BQ9000_ this is the quality manager alert
                            .Link = NavigateURL()
                            .Message = "A Corrective Action has been created and assigned."
                            .UserID = myUser.UserID
                        End With
                        Throwaway = objBQ9000Control.BQ9000_AddAlert(BQ9000_Alert)
                    Else
                        Response.Write("<br>got here but bad" & myUser.DisplayName) <-------------ALWAYS GET HERE
                    End If
                Next


Dylan Barber http://www.braindice.com - Dotnetnuke development classes - skins and modules
 
New Post
5/15/2007 11:52 AM
 

well i think i found the error on this unless i am reading it wrong

in the UserInfo.vb code there is the function IsInRole if you look at it you can see it always returns false

see below

#Region "Public Methods"

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' IsInRole determines whether the user is in the role passed
        ''' </summary>
        ''' <param name="role">The role to check</param>
        ''' <returns>A Boolean indicating success or failure.</returns>
        ''' <history>
        '''     [cnurse] 12/13/2005 created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public Function IsInRole(ByVal role As String) As Boolean

            If IsSuperUser Or role = glbRoleAllUsersName Then
                Return True
            Else
                If Not Roles Is Nothing Then
                    For Each strRole As String In Roles
                        If strRole = role Then
                            Return True
                        End If
                    Next

                End If
            End If

            Return False

        End Function

#End Region

 


Dylan Barber http://www.braindice.com - Dotnetnuke development classes - skins and modules
 
New Post
5/15/2007 11:56 AM
 

Nix that i am reading it wrong


Dylan Barber http://www.braindice.com - Dotnetnuke development classes - skins and modules
 
New Post
5/15/2007 12:07 PM
 

even passing in Registered Users seems to fail


Dylan Barber http://www.braindice.com - Dotnetnuke development classes - skins and modules
 
New Post
5/15/2007 12:35 PM
 

The problem is that the Roles property never gets populated with an array of the role names for the user - except for the currently logged in user when obtained via Me.UserInfo, etc. - and even then not reliably.  With an empty Roles array, IsInRole always returns false. I've been doing the following (where myUser is your UserInfo object ):

Dim rc As New DotNetNuke.Security.Roles.RoleController
myUser.Roles = rc.GetRolesByUser(myUser.UserId, PortalId)
If myUser.IsInRole("Paid Member") Then
    'Do whatever here for the Paid Member
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
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0problem with IsInRolesproblem with IsInRoles


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