0

I am trying to display full name of user from active directory. It works fine on my local. But when I publish this code to IIS on server it shows display name as null. What may be the issue? My account is using windows authentication.

using (var context = new PrincipalContext(ContextType.Domain))
            {
                var principal = UserPrincipal.FindByIdentity(context, User.Identity.Name);
                var displayName = principal?.DisplayName; 
}
Kurkula
  • 6,386
  • 27
  • 127
  • 202

1 Answers1

1

I had to use HostingEnvironment.Impersonate() in order to access my AD properties on my IIS server. (It worked without it on local)

using (HostingEnvironment.Impersonate())
{
  // your code
}

Also, you'd have to change your Application Pool's identity from "AppPoolIdentity" to "NetworkService".

Thomas Sauvajon
  • 1,660
  • 2
  • 13
  • 26