我有以下代码将可分辨名称转换为 sAMAccountName:
Dim de As New DirectoryEntry("LDAP://" & stringDN)
Return CType(de.Properties("samaccountname")(0), String)
它对于我通过的每个 DN 都非常有效,除了一个。我们的域中有一个 AD 组,其中包含“/” - 称之为“程序员/DBA”。该组的 DN 是“程序员/DBA、OU=用户组、DC=mydomain、DC=local”。当我尝试使用此 DN 作为上面的 stringDN 时,收到“未知错误 (0x80005000)”的 COMException。
我的域中的每个其他组/用户都工作正常,并且我在我们的测试域上重复了该问题,其中重命名该组使其不包含“/”可以解决该问题。但是,我无法在生产中执行此操作,所以我陷入了困境。
我可以以某种方式转义这个“/”吗?我必须相信有一个解决方案,这样我才能正确获取该组的属性。
最佳答案
您是否尝试过这样做:
Dim de As New DirectoryEntry("LDAP://" & stringDN.Replace( "/", "\/" ))
Return CType(de.Properties("samaccountname")(0), String)
关于vb.net - "new DirectoryEntry(distinguishedName as string)"不是 't work when DN contains a "/",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/530247/