繁体   English   中英

C#获取LDAP属性语法OID

[英]C# get LDAP attribute syntax OID

我需要检查LDAP属性的语法OID,但找不到任何好的起点。 我使用的是C#,当前使用的是System.DirectoryServices.Protocols(必须保持通用/非Active Directory特定)。

例如,针对Apache Directory Studio,我们可以看到在Active Directory中,“ distinguishedName”属性的语法为OID“ 1.3.6.1.4.1.1466.115.121.1.12”。

任何人都可以朝正确的方向踢我吗?

好吧,我知道了。 我结合使用了这个这个 SO帖子来解决它。 在这里,如果有其他需要的人可以将它缝在一起。 请注意,这适用于Active Directory和OpenLDAP(使用System.DirectoryServices.Protocols)。

var ldapConnection = new LdapConnection( "hostname.tld" );
ldapConnection.AuthType = AuthType.Yours;
ldapConnection.Credential = new NetworkCredential( "username", "password", "domain" );
ldapConnection.SessionOptions.ProtocolVersion = 3;

// Find the subschema first...
var searchRequest = new SearchRequest( null, "(objectClass=*)", SearchScope.Base, "subschemasubentry" );
var searchResponse = (SearchResponse) ldapConnection.SendRequest( searchRequest );

var subSchemaArray = searchResponse.Entries[0].Attributes["subschemasubentry"].GetValues( typeof( String ) );
var subSchema = (String) subSchemaArray[0];

// Now query the LDAP server and get the attribute types
searchRequest = new SearchRequest( subSchema, "(objectClass=*)", SearchScope.Base, "attributetypes" );
searchResponse = (SearchResponse) ldapConnection.SendRequest( searchRequest );

foreach ( string attributeType in searchResponse.Entries[0].Attributes["attributeTypes"].GetValues( typeof( String ) ) )
{
    // This is a chunky string, but the name and syntax OID is listed here
    Console.WriteLine(attributeType);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM