2010-02-09 2 views
2

Active Directory에서 사용자의 생성 날짜를 검색하고 싶습니다. 사용자가 WhenCreated 속성을 가지고 있지만 해당 속성이 내가 작업중인 UserPrincipal 유형에 노출 된 것을 볼 수 없습니다..NET에서 AD 사용자의 생성 날짜를 검색하는 방법은 무엇입니까?

나는 같은 것을 할 싶습니다

var principal = UserPrincipal.FindByIdentity(context, IdentityType.Guid, guid); 
//var createdDate = principal.CreationDate; 

편집 :이 같은 네트워크에있는 다른 컴퓨터에 AD 서버를 질의 IIS 내에서 실행되는 웹 응용 프로그램입니다.

+0

이 데스크톱 또는 브라우저 응용 프로그램인가? –

+0

@Keith - 자사의 asp.net mvc 웹 애플 리케이션 – Ben

답변

9

기본 DirectoryEntry (System.DirectoryServices -namespace의 일부)를 가져와야합니다.

당신은 문자열로 날짜를 얻을이 확장 방법을 사용할 수 있습니다 :이 같은

public static String GetProperty(this Principal principal, String property) 
{ 
    DirectoryEntry directoryEntry = principal.GetUnderlyingObject() as DirectoryEntry; 
    if (directoryEntry.Properties.Contains(property)) 
     return directoryEntry.Properties[property].Value.ToString(); 
    else 
     return String.Empty; 
} 

사용 :

var createdDate = principal.GetProperty("whenCreated"); 
관련 문제