C# 未处理DirectoryServicesMexception目录服务中的无效DN语法
我试图通过c使用LDAP查询连接到我们的广告C# 未处理DirectoryServicesMexception目录服务中的无效DN语法,c#,.net,active-directory,ldap,C#,.net,Active Directory,Ldap,我试图通过c使用LDAP查询连接到我们的广告 DirectoryEntry de = new DirectoryEntry("LDAP://ldap.mysite.gov.sa:389/ou=mysiteCSP,ou=Government CA,o=National Center ,c=LA"); // de.RefreshCache(); DirectorySearcher dsearch = new DirectorySearcher(de); dsearch.Filter = "(cn=
DirectoryEntry de = new DirectoryEntry("LDAP://ldap.mysite.gov.sa:389/ou=mysiteCSP,ou=Government CA,o=National Center ,c=LA");
// de.RefreshCache();
DirectorySearcher dsearch = new DirectorySearcher(de);
dsearch.Filter = "(cn=aabs@mysite.gov.sa)"; //Search how you want. Google "LDAP Filter" for more.
SearchResultCollection rc = dsearch.FindAll();
X509Certificate stt = new X509Certificate();
我得到了这个错误:-
System.DirectoryServices.DirectoryServicesCOMException was unhandled
HResult=-2147016654
Message=An invalid dn syntax has been specified.
Source=System.DirectoryServices
ErrorCode=-2147016654
ExtendedError=13
ExtendedErrorMessage=Invalid DN syntax
StackTrace:
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
at System.DirectoryServices.DirectorySearcher.FindAll()
at NCDCToolkit.Utilities.LDAPQuery.query(String csp_name, String query) in c:\Users\yrajhi\Documents\Visual Studio 2012\Projects\NCDCToolkit\NCDCToolkit\Utilities\LDAPQuery.cs:line 23
at NCDCToolkit.Program.Main(String[] args) in c:\Users\yrajhi\Documents\Visual Studio 2012\Projects\NCDCToolkit\NCDCToolkit\Program.cs:line 46
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
有什么帮助吗?ou=mysiteCSP,ou=Government CA,o=National Center,c=LA
^^这不是有效的DN。查看Active Directory中组织单位的DifferentizedName属性以获取正确的名称
它们的格式应该是ou=myou,dc=mydomain,dc=local或类似的格式。实际上它是有效的,可能减去国家中心的尾随空格。