vb.net - "new DirectoryEntry(distinguishedName as string)"不是 't work when DN contains a "/"

标签 vb.net active-directory directoryservices directoryentry distinguishedname

我有以下代码将可分辨名称转换为 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/

相关文章:

vb.net - 字符串中区分大小写/不区分大小写的搜索文本

c# - 存储 Kerberos 身份验证以供以后模拟

powershell - 使用PowerShell更改.csv中的samaccountname

c# - ASP.NET MVC Windows Authentiaction 和 DirectoryServices - 获取当前用户的邮件地址引发 InvalidCastException

vb.net - Npgsql 可以转储/恢复整个数据库吗?

.net - 如何在vb.net中对结构数组的相似元素求和?

c# - 在没有硬编码信息的情况下获取当前 AD 站点中最近的域 Controller

c# - 从 Active Directory 中获取启用的帐户

.net - 调试动态加载的程序集

active-directory - SonarQube LDAP 插件 Active Directory 嵌套组