【问题标题】:Find Users e-mail based on the current IPrincipal根据当前 IPrincipal 查找用户电子邮件
【发布时间】:2012-04-09 14:16:34
【问题描述】:

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

IPrincipal principal = HttpContext.Current.User;

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

【问题讨论】:

  • 这个link 可以帮助你。

标签: c# asp.net active-directory


【解决方案1】:
using (var context = new PrincipalContext(ContextType.Domain)) {
  using (var user = UserPrincipal.FindByIdentity(context, userName)) {
    if (user != null) {
       return user.EmailAddress;
    }
  }
}

【讨论】:

  • 请提高解释它的答案的质量。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-15
  • 1970-01-01
  • 2017-09-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多