簡體   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