View Single Post
 
Old 06-03-2013, 11:00 AM
james2k2's Avatar
james2k2 james2k2 is offline
Junior Contributor
 
Join Date: Oct 2002
Posts: 352
Default

Just an update really. The code below is my modified function that will do the aforementioned checking properly. A side note would be that this forces a check against the Domain specified, whereas the way it was working previously would mean it could potentially match builtin or any domain (security issue). I'm not sure if this is exactly a solid solution so any input would be great. Many thanks

Code:
    Public Function UserIsInRole(RoleString As String, Optional NetDomain As String = "") As Boolean
        'checks to see if a comma delimited string of roles is part of the currently logged in user

        Dim SplitRoles() As String = Strings.Split(RoleString, ",")         'break down the roles to an array
        Dim RoleCount As Integer = 0                                        'set role count to zero

        If NetDomain <> "" Then NetDomain &= "\"

        For Each Role As String In SplitRoles                               'check each role in the array against the user
            If User.IsInRole(NetDomain & Role) Then RoleCount += 1
            If User.Identity.Name = NetDomain & Role Then RoleCount += 1
        Next


        If RoleCount > 0 Then                                               'return true if the user was found to match any roles supplied
            Return True
        Else
            Return False
        End If
    End Function
__________________
I don't have a signature
Reply With Quote