2

我在 ASP.net MVC 应用程序中使用 Windows 身份验证。我想查询 Active Directory 以获取基于当前用户的用户电子邮件地址:

IPrincipal principal = HttpContext.Current.User;

有没有办法可以使用 Active Directory 来查询他们的电子邮件地址?

4

1 回答 1

-1
using (var context = new PrincipalContext(ContextType.Domain)) {
  using (var user = UserPrincipal.FindByIdentity(context, userName)) {
    if (user != null) {
       return user.EmailAddress;
    }
  }
}
于 2016-04-14T09:49:04.147 回答