通过在C#中的System.DirectoryServices查询定制LDAP的财产? [英] Querying custom LDAP property via System.DirectoryServices in C#?

查看:324
本文介绍了通过在C#中的System.DirectoryServices查询定制LDAP的财产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了OpenLDAP服务器的自定义LDAP模式是如下:

I have a custom LDAP schema installed on my OpenLDAP server which is as follows:

attributeType ( 999.0.01
    NAME 'picturePath'
    EQUALITY caseIgnoreMatch
    SUBSTR caseIgnoreSubstringsMatch
    SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1024}
    )

objectClass ( 999.1.01
    NAME 'indieStackTeam'
            DESC 'Team definition for IndieStack'
    SUP groupOfUniqueNames
    STRUCTURAL
            MAY     ( picturePath )
    )

在我的ASP.NET MVC 2应用程序,我查询了picturePath财产像这样(和它证实picturePath存在密钥列表):

In my ASP.NET MVC 2 application, I'm querying for the picturePath property like so (and it is confirmed that picturePath exists in the list of keys):

this.Picture = properties["picturePath"].Value as string;

当我试图.NET 3.5下做到这一点,我得到以下异常:

When I attempt to do this under .NET 3.5 I get the following exception:

[COMException (0x8000500c): Unknown error (0x8000500c)]   
    System.DirectoryServices.PropertyValueCollection.PopulateList() +347013
    System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName) +49   
    System.DirectoryServices.PropertyCollection.get_Item(String propertyName) +150

但是,当相同的code单下运行(在同一台服务器上的OpenLDAP),它完美的罚款。客户如LDAPAdmin也可以正确读取picturePath属性。

However, when the same code runs under Mono (on the same server as OpenLDAP) it works perfectly fine. Clients such as LDAPAdmin can also read the picturePath property correctly.

越是如此,只有当我去,它无法读取值;我能看到的属性是那里的键列表,我只是不能访问它。

More so, it's only when I go to read the value that it fails; I can see the property is there in the keys list, I just can't access it.

不幸的是未知的错误并没有告诉我很多关于什么错,但我发现了.NET实现的System.DirectoryServices是非常片状(你得到同样的未知错误,如果你连接到LDAP服务器使用小写在DC =')。

Unfortunately unknown error doesn't tell me a lot about what's going wrong, but I'm finding the .NET implementation of System.DirectoryServices is very flaky (you get the same unknown error if you connect to the LDAP server using lowercase in 'DC=').

有没有人有这个问题之前,如果是这样,它是如何解决的?

Has anyone had this problem before and if so, how is it solved?

推荐答案

看来,.NET LDAP客户端需要一个正确的形成OID的属性类型和对象类。

It seems that the .NET LDAP client expects a correctly formed OID for attribute types and object classes.

您会注意到,我用的是形式999.X.YY,这虽然他们可能是语法正确的,通常不会在现实世界中遇到的OID。我的猜测是LDAP客户端解析的OID由于这些不符合的期望是什么,它​​抛出一个错误。

You'll note that I was using OIDs of the form 999.X.YY, which while they might be syntactically correct, aren't usually encountered in the real world. My guess is the LDAP client parses OIDs and since these don't conform to what is expected, it throws an error.

我改变了的OID为1.3.6.1.4.1.40000.1.3.1分别1.3.6.1.4.1.40000.1.4.1(我还申请了一笔,这将给我一个指定的号码,而不是'40000' ),刷新服务器架构并重新创建条目和LDAP客户端现在可以正确读取自定义属性。

I changed the OIDs to 1.3.6.1.4.1.40000.1.3.1 and 1.3.6.1.4.1.40000.1.4.1 respectively (I've also applied for a PEN, which will give me an assigned number instead of '40000'), refreshed the schema in the server and recreated the entries and the LDAP client now correctly reads the custom attributes.

这篇关于通过在C#中的System.DirectoryServices查询定制LDAP的财产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆