English 中文(简体)
如何从C#System.DirectoryService调用引发的异常中识别LDAP错误?
原标题:How to identify LDAP errors from exceptions thrown by C# System.DirectoryService calls?
  • 时间:2010-10-20 21:57:53
  •  标签:
  • c#
  • .net
  • ldap

我正在编写一个.NET应用程序来查询LDAP服务器,但我不知道如何查看异常并弄清楚LDAP端发生了什么。我正在使用DirectoryServices,并试图避免任何特定于ActiveDirectory的内容。

我创建了一个DirectorySearcher,然后执行

try
{  
    SearchResult result = searcher.FindOne();
}
catch(Exception e)
{
    // now what?
}

我预计LDAP端会发生某些类型的错误,如找不到用户、帐户被禁用等,我想确定这些特定的错误。是否有特定的预期类型?

我注意到innerException有一个_COMPlusExceptionCode。这是LDAP端出现问题的可靠指标吗?我找不到这些异常代码的枚举。

有什么建议吗?

最佳回答

有一个所有ADSI错误代码的列表此处,其中包含通用COM和通用ADSI错误,以及特定的ADSI 2.0的LDAP错误代码

众所周知,LDAP错误很难处理——通常情况下,你只会得到一个“服务器无法执行”或类似的问题,而没有太多解释是什么导致服务器无法完成其工作。

问题回答

现在调用.ToString()并查看人类可读的文本。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签