相关疑难解决方法(0)

无法在System.DirectoryServices.AccountManagement.GroupPrincipal中转换类型的对象

我正在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)

c# iis

19
推荐指数
2
解决办法
2万
查看次数

使用 DirectoryServices.AccountManagement,如何获取 Active Directory 安全组的电子邮件地址?

我在活动目录中有一个安全组(如下图所示),它有一个关联的电子邮件地址。如何获取群组的电子邮件地址?该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)

安全组

.net c# directoryservices active-directory

5
推荐指数
2
解决办法
3121
查看次数

标签 统计

c# ×2

.net ×1

active-directory ×1

directoryservices ×1

iis ×1