【发布时间】:2015-08-18 03:35:07
【问题描述】:
我正在使用 .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 权限。
This 链接有一个解决方案,但它适用于IIS,它对我不起作用。
This 解决方案也不起作用。
【问题讨论】:
-
试试
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "yourdomain.com", "CN=users,CN=mydomain,CN=workgroup", ContextOptions.SecureSocketLayer | ContextOptions.Negotiate, userName, password);由于您已经拥有管理员权限,只需提供域名即可尝试绑定。PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "yourdomain.com"); -
我使用了
SecureSocketLayer得到了这个错误The ContextOptions passed are invalid for this store type. Either Negotiate or SimpleBind must be specified and they cannot be combined. -
您似乎没有安装
SSL。试试SimpleBind。 -
@Burzum 您第一条评论中的第二条建议奏效了,我刚刚使用了该域并且它奏效了。
-
请打开一个新问题并提供有关您的 IIS 的一些详细信息。
标签: c# .net active-directory directoryservices principalcontext