2011-04-28 4 views
0

여기에 설명 된 IsActive 메서드를 구현하려고하는데 Is Account Active,하지만 개체 참조가 개체 인스턴스로 설정되지 않습니다.디렉터리 항목 - 계정 활성

 private bool IsActive(DirectoryEntry de) 
    { 
     DirectoryEntry myEntry = GetDirectoryEntry(); 
     if (myEntry.NativeGuid == null) return false; 

     int flags = (int)myEntry.Properties["userAccountControl"].Value; 

     if (!Convert.ToBoolean(flags & 0x0002)) return true; else return false; 

     return false; 
    } 
    private void SubmitData() 
    { 
     System.Guid guid = Guid.NewGuid(); 
     logInfo.IPaddress = IPAddress; 

     if (!String.IsNullOrEmpty(txtUser.Text)) 
     { 
      string username = txtUser.Text.ToString(); 
      if (IsActive(de) != false) 
      { 
       if (DateTime.Now.Subtract(passwordLastSet).TotalHours > 1) 
       { 
        lblPasswordLastSet.Text = passwordLastSet.ToString(); 
        lblStatus.Text = "all is good"; 
       } 
       else 
       { 
        lblStatus.Text = "oops, you reset your password less than 24 hours ago!"; 
        lblPasswordLastSet.Text = passwordLastSet.ToString(); 
       } 
      } 
      else 
      { 
       lblStatus.Text = "your account is not active"; 
      } 
     } 
    } 

답변

1

당신이 .NET 3.5 및 최대에 있다면, 당신은 System.DirectoryServices.AccountManagement (S.DS.AM) 네임 스페이스를 확인해야합니다. 여기에 대한 모든 읽기 :

// set up domain context 
PrincipalContext ctx = new PrincipalContext(ContextType.Domain); 

// find user by name 
UserPrincipal user = UserPrincipal.FindByIdentity("John Doe"); 

if(user != null) 
{ 
    // check if account is locked out 
    if(user.IsAccountLockedOut) 
    { 
     // do something if locked out.... 
    } 
} 

새로운 S.DS.AM 그것을 만드는 :

기본적으로 Managing Directory Security Principals in the .NET Framework 3.5

, 당신은 AD에서 사용자 및/또는 그룹을 쉽게 찾을 도메인 컨텍스트를 정의 할 수 있습니다 광고에서 사용자 및 그룹과 놀기가 정말 쉽습니다.

+0

감사합니다. 내가 제안한 경로를 이용하겠습니다. – Jason