我從這個代碼中使用:如何獲取Active Directory中的用戶組?
List<GroupPrincipal> result = new List<GroupPrincipal>();
// establish domain context
PrincipalContext MyDomain = new PrincipalContext(ContextType.Domain);
// find your user
UserPrincipal user = UserPrincipal.FindByIdentity(MyDomain , username);
// if found - grab its groups
if(user != null)
{
PrincipalSearchResult<Principal> groups = user.GetAuthorizationGroups();
// iterate over all groups
foreach(Principal p in groups)
{
// make sure to add only group principals
if(p is GroupPrincipal)
{
result.Add(p);
}
}
}
,但在這條線(user.GetAuthorizationGroups()
)我得到了一個異常
This server is not operational
我想在wpf應用程序中使用此鱈魚 –
可以嘗試使用'user.GetGroups()'而不是'.GetAuthorizationGroups()' - 做到這一點工作?? –
user.GetGroups()也有這個異常 –