2

I am using Windows Authentication in an ASP.net MVC application. I would like to query Active Directory to get a users e-mail address based on the current user:

IPrincipal principal = HttpContext.Current.User;

Is there a way I can use Active Directory to query for their e-mail address?

Dismissile
  • 32,564
  • 38
  • 174
  • 263
  • This [link](http://weblogs.asp.net/jpinquie/archive/2008/02/06/how-to-get-domain-user-information-from-active-directory-in-c.aspx) may help you out. – mreyeros Apr 09 '12 at 14:23

1 Answers1

-1
using (var context = new PrincipalContext(ContextType.Domain)) {
  using (var user = UserPrincipal.FindByIdentity(context, userName)) {
    if (user != null) {
       return user.EmailAddress;
    }
  }
}