问题描述
我编码一些C#的Active Directory,并试图无休止地得到这个工作,都无济于事。下面code ++工程和code紧随其后不会:
I'm coding some c# against Active Directory and have tried endlessly to get this to work to no avail. The following code works and the code that follows it does not:
在code以下使用WINNT://+ Environment.MachineName +电脑进行连接,并能正常工作
The code below is using "WinNT://" + Environment.MachineName + ",Computer" to make the connection and works fine.
DirectoryEntry localMachine = new DirectoryEntry
("WinNT://" + Environment.MachineName + ",Computer");
DirectoryEntry admGroup = localMachine.Children.Find
("Administrators", "group");
object members = admGroup.Invoke("members", null);
foreach (object groupMember in (IEnumerable)members)
{
DirectoryEntry member = new DirectoryEntry(groupMember);
output.RenderBeginTag("p");
output.Write(member.Name.ToString());
output.RenderBeginTag("p");
}
base.Render(output);
我现在试图改变行:
I'm now trying to change the line:
"WinNT://" + Environment.MachineName + ",Computer"
到
"LDAP://MyDomainControllerName"
但似乎不管我尝试替代价值MyDomainControllerName它不会工作。
but it seems no matter what value I try in place of the value 'MyDomainControllerName' it wont work.
要获得MyDomainControllerName价值我右键点击我的电脑并复制计算机名称值,建议其他地方,但并没有工作。
To get the 'MyDomainControllerName' value I right clicked on MyComputer and copied the computer name value as suggested elsewhere but this didn't work.
当我尝试使用LDAP:上面这会导致下面的错误// RootDSE的选项:
When I try using the LDAP://RootDSE option above it results in the following error:
位于路径LDAP的Active Directory对象:// RootDSE的不是一个容器
The Active Directory object located at the path LDAP://RootDSE is not a container
这是与成员方法,你提一个问题吗?
Is this a problem with the member methods as you mention?
推荐答案
当连接到公元使用.NET Framework,则可以使用无服务器的结合,也可以指定一个服务器来使用,每次(服务器绑定)。
When connecting to AD using the .NET Framework, you can use "serverless" binding or you can specify a server to use everytime (server bound).
下面是使用的例子两个:
Here's an example of using both:
// serverless
DirectoryEntry rootConfig = new DirectoryEntry("LDAP://dc=domainname,dc=com");
// server bound
DirectoryEntry rootEntry = new DirectoryEntry("LDAP://domainControllerName/dc=domainName,dc=com");
我觉得你在哪里误入歧途是你忘了,包括在FQDN上后,你的域名。希望这有助于。
I think where you were going astray is you forgot to include the FQDN for your domain on the end. Hope this helps.
这篇关于C#对通过LDAP的Active Directory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!