Saturday, October 5, 2013

System.DirectoryServices.AccountManagement PrincipalContext not picking up Current Logged In User Credentials

Hi,


Not sure if this is the correct place to post this question, but I'm trying to implement a Web Part using the Active Directory Services System.DirectoryServices.AccountManagement and am having issues with the credentials when trying to create a new PrincipalContext object.


I've tried a number of options but for some reason I always get access denied when I try to create a new Active Directory User even though I'm logged in with a user that has full delegate rights to create users in Active Directory.


The code to create the PrincipalContext is below:



PrincipalContext domainContext = new PrincipalContext(
ContextType.Domain,
null,
Container);

Where Container is a variable that holds the name of the actual OU I'm working with. I've also tried it with ContextOptions.Negotiate in the constructor.


If I put the Username and Password into the constructor then it works fine without any issues - however I can't do this in my implementation as different users will have access to the Web Part and they will have delegated rights to a specific OU in Active Directory - so it should automatically pick up their current credentials.


The Web Application is setup in classic mode using NTLM.


Any ideas.


Thanks.



No comments:

Post a Comment