我正在UserPrincipal.Current.ToString()域中使用方法来获取具有有效域的域用户当前记录.但当我在一个字符串中显示它时,它在IIS服务器中托管时给出错误:
Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal'
to type 'System.DirectoryServices.AccountManagement.UserPrincipal'.
Run Code Online (Sandbox Code Playgroud) 我在活动目录中有一个安全组(如下图所示),它有一个关联的电子邮件地址。如何获取群组的电子邮件地址?该GroupPrincipal对象没有任何电子邮件地址属性。
这就是我检索所有组的方式:
using (PrincipalContext context = new PrincipalContext(DirectoryContextType, Domain)) {
using (var groupSearcher = new GroupPrincipal(context)) {
using (var searcher = new PrincipalSearcher(groupSearcher)) {
foreach (GroupPrincipal group in searcher.FindAll()) {
//How do I get the e-mail address?
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
