“new DirectoryEntry(distinguishedName as string)” doesn't work when DN contains a “/”

主宰稳场 提交于 2019-12-06 12:37:33

问题


I have the following code to convert a distinguishedName to a sAMAccountName:

Dim de As New DirectoryEntry("LDAP://" & stringDN)
Return CType(de.Properties("samaccountname")(0), String)

It works great for every DN I pass it, except for one. We have an AD group on our domain that has a "/" in it - call it "Programmers/DBAs". The DN for this group is "Programmers/DBAs,OU=User Groups,DC=mydomain,DC=local". When I try to use this DN as the stringDN above, I get a COMException of "Unknown error (0x80005000)".

Every other group/user in my domain works fine, and I've duplicated the issue on our test domain, where renaming the group so it doesn't contains a "/" resolves the problem. However, I'm not able to do this in production, so I'm stuck.

Can I escape this "/" somehow? I've got to believe there's a solution around this so that I can get the properties of this group properly.


回答1:


Have you tried doing:

Dim de As New DirectoryEntry("LDAP://" & stringDN.Replace( "/", "\/" ))
Return CType(de.Properties("samaccountname")(0), String)


来源:https://stackoverflow.com/questions/530247/new-directoryentrydistinguishedname-as-string-doesnt-work-when-dn-contains

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!