Search 如何在Active Directory中按全名查找电子邮件?

Search 如何在Active Directory中按全名查找电子邮件?,search,active-directory,Search,Active Directory,我想使用Active Directory搜索用户的电子邮件。可用的是用户的全名(例如“John Doe”,用于包含电子邮件的电子邮件”jdoe@example.com"). 从我搜索的内容来看,它与我想要做的很接近——只是过滤器设置为“SAMAccountName”,这不是我所拥有的 除非我误解了,否则我只需要选择正确的属性并以同样的方式输入全名。不幸的是,我不知道这个属性是什么,显然没有人需要询问以这种方式搜索信息,这是一个相当大的列表(msdn*microsoft*com/en-us/li

我想使用Active Directory搜索用户的电子邮件。可用的是用户的全名(例如“John Doe”,用于包含电子邮件的电子邮件”jdoe@example.com"). 从我搜索的内容来看,它与我想要做的很接近——只是过滤器设置为“SAMAccountName”,这不是我所拥有的

除非我误解了,否则我只需要选择正确的属性并以同样的方式输入全名。不幸的是,我不知道这个属性是什么,显然没有人需要询问以这种方式搜索信息,这是一个相当大的列表(msdn*microsoft*com/en-us/library/ms675090(v=VS.85)*aspx,stackoverflow不允许我链接2个超链接,因为我没有10个rep)的属性

是否有人知道如何通过使用用户全名通过Active Directory查找来获取用户的电子邮件地址?

使用3.5 System.DirectoryServices.AccountManagement.dll,您可以使用UserPrincipal FindByIdentity方法:

UserPrincipal.FindByIdentity(context, IdentityType.Name, "Lastname, Firstname");
此调用通常封装在几个using语句中,如下所示:

using (var ctx = new PrincipalContext(ContextType.Domain))
{     
    using (var userPrincipal = UserPrincipal.FindByIdentity(ctx, IdentityType.Name, user))
    {
        return userPrincipal == null ? "" : userPrincipal.EmailAddress;
    }
 }
使用3.5 System.DirectoryServices.AccountManagement.dll,可以使用UserPrincipal FindByIdentity方法:

UserPrincipal.FindByIdentity(context, IdentityType.Name, "Lastname, Firstname");
此调用通常封装在几个using语句中,如下所示:

using (var ctx = new PrincipalContext(ContextType.Domain))
{     
    using (var userPrincipal = UserPrincipal.FindByIdentity(ctx, IdentityType.Name, user))
    {
        return userPrincipal == null ? "" : userPrincipal.EmailAddress;
    }
 }

谢谢你,先生,我到处寻找这个解决方案。工作起来很有魅力!谢谢你,先生,我到处寻找这个解决方案。工作起来很有魅力!