views:

510

answers:

2

How would I go about this?

I know that using Dim currUser As String = Request.ServerVariables("LOGON_USER") retunrs the Domain\Username, but I want to know what Group that user is in say in Active Directory.

Is this possible?

Thanks in advance for any help.

+2  A: 

Do you want a list of the groups? Or do you want to check if the user is a member of a specific group?

If the latter, you can use WindowsPrincipal.IsInRole() to check if the user belongs to a specific group:

http://msdn.microsoft.com/en-us/library/fs485fwh.aspx

For example, if you want to check if the user is an Administrator you can use:

If Page.User.IsInRole("BUILTIN\Administrators") Then
    ' Do something
End If
Brannon
+2  A: 

You can use UserPrincipal.GetAuthorizationGroups Method

imports System.DirectoryServices.AccountManagement
dim name as string = Request.ServerVariables("LOGON_USER") 
dim user As UserPrincipal = UserPrincipal.FindByIdentity( new PrincipalContext( ContextType.Domain ), name)
dim groups As PrincipalSearchResult(Of Principal)= user.GetAuthorizationGroups()
Wael Dalloul