0

我正在使用 .NET Forms 应用程序中的这段代码来尝试创建一个 PrincipalContext 对象。

var oPrincipalContext = new PrincipalContext(
                ContextType.Domain, 
                "mydomain.workgroup",
                "CN=users,CN=mydomain,CN=workgroup", 
                ContextOptions.Bind,                    
                "ADAdmin", 
                "ADAdminPassword");

我也试过这个,但得到了同样的错误。

var oPrincipalContext = new PrincipalContext(
                ContextType.Domain, 
                "mydomain.workgroup",
                "CN=users,CN=mydomain,CN=workgroup", 
                ContextOptions.Negotiate,                    
                "ADAdmin", 
                "ADAdminPassword");

我也尝试过ADAdmin@mydomain.workgroup作为用户ID。

我收到此错误

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()

我以在 AD 中具有 DomainAdmin 权限的用户身份登录。

我运行它的计算机在 AD 中具有 DomainAdmin 权限。

链接有一个解决方案,但它IIS适用于我,但对我不起作用。

解决方案也不起作用。

4

1 回答 1

2

由于您提到用户已经具有管理员权限,您只需要指定ContextType和您的Domain.

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "yourdomain.com");
于 2015-08-18T04:23:54.270 回答