UserPrincipal from Active Directory

Mahdi

New Member
I have problem with getting UserPrincipal from Active Directory. First of all I have used on my local environment (using not IIS but ASP.NET development Server):\[code\]User usr = new User();usr.SoeId = Request.ServerVariables["LOGON_USER"];usr.IP = Request.ServerVariables["REMOTE_ADDR"];usr.FirstName = UserPrincipal.Current.GivenName;usr.LastName = UserPrincipal.Current.Surname;\[/code\]And it works fine. I got what I want. But when I install application on testing environment I got error "Object reference not set to an instance of an object". I have tried solution from here.\[code\]using (PrincipalContext pc = new PrincipalContext(ContextType.Domain)){ UserPrincipal up = UserPrincipal.FindByIdentity(pc, usr.SoeId); return up.DisplayName; // or return up.GivenName + " " + up.Surname;}\[/code\]But it does not work.I use windows authentication. Impersonation is set to true. Please help me.
 
Back
Top