2013-01-04 2 views
4

가능한 중복 :
How to get the groups of a user in Active Directory? (c#, asp.net)현재 Windows 사용자로 로그인 하시겠습니까?

는 현재 System.DirectoryServices.AccountManagement 네임 스페이스를 사용하여 로그온 한 사용자가 얻을 수있는 방법이 있나요?

Dim wi As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent() 

    Dim fullName As String = wi.Name.ToString 

    Dim loggedOnUser = fullName.Substring(fullName.IndexOf("\") + 1) 

    Console.WriteLine("The currently logged on user is {0}", loggedOnUser) 

을하지만 나는 그들이 일반 텍스트에 속하는 그룹 이름과 같은 현재 사용자에 대한 자세한 정보를 원하는, 그리고 AccountManagement 공간이를 제공하는 경우 궁금 해서요 : 나는 다음과 같은 사용했습니다. 당신이 뭔가를 찾고있다

For Each item As IdentityReference In wi.Groups 
    Console.WriteLine(item.ToString()) 
Next 
+1

에서 구글의 작은 도움으로 그것을 발견? –

+0

어떤 종류의 정보를 원하십니까? GetCurrent()에서 반환 된 WindowsIdentity-object에는 Name보다 많은 정보가 들어 있습니다. http://msdn.microsoft.com/en-us/library/system.security.principal.windowsidentity.aspx – Abbas

+0

죄송합니다. 명시해야합니다. 그들이 속한 그룹 이름을 일반 텍스트로 가져와야하고 그 작업을 수행하는 방법을 알아낼 수 없습니다. – Cuthbert

답변

5

:

이 그냥 이해 할 수없는 숫자의 문자열을 반환 사용하십니까?

using (PrincipalContext context = new PrincipalContext(ContextType.Domain)) 
{ 
    UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "login"); 
    foreach (var group in user.GetGroups()) 
    { 
     Console.WriteLine(group.Name); 
    } 
} 

편집

는 : 어떤 종류의 정보 : "나는 현재 사용자에 대한 자세한 정보를 원하는"유래 ;-) Active directory : get groups where a user is member

관련 문제