2014-06-26 28 views
0

我试图通过c#使用LDAP查询连接到我们的AD。DirectoryServicesCOMException未处理目录服务中的无效DN语法

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 = "([email protected])"; //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: 

任何帮助吗?

回答

0

ou=mysiteCSP,ou=Government CA,o=National Center ,c=LA

^^这不是一个有效的DN。查看Active Directory中组织单位的distinguishedName属性,以获取正确的名称。

它们应该采用格式ou=myou,dc=mydomain,dc=local或类似的格式。

+0

其实它是有效的,也许减去国家中心的尾部空间。 –

相关问题