I am using this code from a .NET Forms application to try and create a PrincipalContext object.
var oPrincipalContext = new PrincipalContext(
ContextType.Domain,
"mydomain.workgroup",
"CN=users,CN=mydomain,CN=workgroup",
ContextOptions.Bind,
"ADAdmin",
"ADAdminPassword");
I also tried this with but got the same error.
var oPrincipalContext = new PrincipalContext(
ContextType.Domain,
"mydomain.workgroup",
"CN=users,CN=mydomain,CN=workgroup",
ContextOptions.Negotiate,
"ADAdmin",
"ADAdminPassword");
I have also tried ADAdmin@mydomain.workgroup
as the user id.
I am getting this error
Message=An operations error occurred.
StackTrace= at System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInit()
at System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit()
at System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()
at System.DirectoryServices.AccountManagement.PrincipalContext.get_ConnectedServer()
at WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e)
InnerException=An operations error occurred.
StackTrace= at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_SchemaEntry()
at System.DirectoryServices.AccountManagement.ADStoreCtx.IsContainer(DirectoryEntry de)
at System.DirectoryServices.AccountManagement.ADStoreCtx..ctor(DirectoryEntry ctxBase, Boolean ownCtxBase, String username, String password, ContextOptions options)
at System.DirectoryServices.AccountManagement.PrincipalContext.CreateContextFromDirectoryEntry(DirectoryEntry entry)
at System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInit()
I am logged in as a user with DomainAdmin privileges in AD.
The computer I am running this from has DomainAdmin privileges in AD.
This link has a solution but it is for IIS
and it didn't work for me.
This solution didn't work either.
Since you have mentioned that the user has already admin privileges, you only need to specify ContextType
and your Domain
.
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "yourdomain.com");