2011-11-30 12 views
0

如果用戶從AD中刪除,用戶仍然存在於SharePoint中。現在我想檢查用戶是否存在於AD中,那麼是否有任何sharepoint對象模型可以做到這一點?檢查AD中是否存在Sharepoint用戶

在此先感謝。

+0

您應該配置用戶配置文件同步來獲得更新的信息到SharePoint。 – Shoban

回答

1

如果用戶位於域用戶組中,它將收集該用戶組下的所有用戶,並將列表循環到嘗試查找當前用戶的列表中。如果找到用戶,則返回true,否則返回false

檢查這篇文章Check Whether User Exists in Active Directory,其中包括一些安全相關的問題,以達到要求。

// Get ad users in the groups. Since MOSS does 
        // not support nested groups 
        // this will always be a collection of AD users 
        // and groups 
        foreach (SPUser user in group.Users) 
        { 
         // Check if this is a Group 
         if (!user.IsDomainGroup) 
         { 
          // Verify if the user name matches the user name in group 
          if (user.LoginName.ToUpper().Equals(upperCaseUserName)) 
          { 
           // if a match is confirmed, return from the method. 
           // There is no need to continue 
           userIsInGroup = true; 
           return; 
          } 
         } 
         else { 
         // If the AD entity is a User Group, 
         // then check for users in that group 
         if (IsUserInADGroup(web, user.LoginName, 
          username, out reachedMax)) 
         { 
          userIsInGroup = true; 
          return; 
         } 
        } 

希望這有助於..