DirectoryServicesCOMException未处理目录服务中的无效DN语法

时间:2014-06-26 06:56:34

标签: c# .net active-directory ldap

我尝试通过c#使用LDAP Query连接到我们的AD。

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: 

任何帮助?

1 个答案:

答案 0 :(得分:0)

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

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

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