Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Group Membership using IsInRole

Status
Not open for further replies.

Qamgine

Programmer
Mar 6, 2001
126
US
I have searched for IsInRole in this forum and I found one topic ( that addresses this issue, but the solution listed did not work.

Here is my code:
----------------
Code:
Imports System
Imports System.Security
Imports System.Security.Principal
Imports System.Threading

Module modUserInfo
    Public Function IsMemberOf(ByVal Group As String) As Boolean
        Try
            Dim aID As Principal.WindowsIdentity
            Dim aName As String = aID.GetCurrent.Name
            Dim aDomain As String = aName.Substring(0, aName.IndexOf("\") + 1)

            AppDomain.CurrentDomain.SetPrincipalPolicy(Principal.PrincipalPolicy.WindowsPrincipal)
            Dim wp As WindowsPrincipal = Thread.CurrentPrincipal
            Return wp.IsInRole(aDomain & Group)

            'Solution from: [URL unfurl="true"]http://www.tek-tips.com/viewthread.cfm?qid=541090[/URL]
            '----------------------------------------------------------------
            'AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
            'Return Thread.CurrentPrincipal.IsInRole(aDomain & Group)
        Catch ex As Exception
            RaiseError(ex)
            Return False
        End Try
    End Function

    Public Function IsMemberOf(ByVal Group As WindowsBuiltinRole) As Boolean
        Try
            AppDomain.CurrentDomain.SetPrincipalPolicy(Principal.PrincipalPolicy.WindowsPrincipal)

            Dim WP As WindowsPrincipal
            WP = Thread.CurrentPrincipal
            Return WP.IsInRole(Group)
        Catch ex As Exception
            RaiseError(ex)
            Return False
        End Try
    End Function
End Module

The second function that uses WindowsBuiltInRole works perfectly. The first function that allows for a string to be passed does not.

I commented out the solution from because that didn't work either.


I appreciate any help that would help resolve this issue.

Thank you,

Qamgine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top