Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Lightweight Directory Access Protocol Uniform Resource Identifier (LDAPUri)

0.00/5 (No votes)
28 Feb 2008 1  
An Attempt to make Uniform resource identifier for the Lightweight Directory Access Protocol
figure1.png

Introduction

This is an attempt to make a Uniform Resource Identifier for the Lightweight Directory Access Protocol (LDAP).

Background

While working with DirectoryEntry, I encountered some errors due to the LDAP Path. So I decided to make an attempt to create a Uniform Resource Identifier for the LDAP path.

Using the Code

Using the LDAPUri class is straight forward.

The following code demonstrates building an LDAP path part-wise:

LDAPUri LDAPUriTest = new LDAPUri();
LDAPUriTest.Protocol = LDAPProtocol.LDAP;
LDAPUriTest.Attributes.Add(new LDAPAttribute
    (LDAPAttributeType.CommonNames, "Computers"));
LDAPUriTest.Attributes.Add(new LDAPAttribute(LDAPAttributeType.DomainComponent, "www"));
LDAPUriTest.Attributes.Add(new LDAPAttribute
    (LDAPAttributeType.DomainComponent, "codeproject"));
LDAPUriTest.Attributes.Add(new LDAPAttribute(LDAPAttributeType.DomainComponent, "com"));

The above code returns the following:

  • LDAPUriTest.Port - 389
  • LDAPUriTest.Protocol - LDAPProtocol.LDAP
  • LDAPUriTest.LDAPPathShort - CN=Computers,DC=www,DC=codeproject,DC=com
  • LDAPUriTest.LDAPPath - LDAP://CN=Computers,DC=www,DC=codeproject,DC=com

The following code demonstrates building an LDAP path by throwing the string direct into the LDAPUri Class constructor:

LDAPUri LDAPUriTest = new LDAPUri(LDAP://CN=Computers,DC=www,DC=codeproject,DC=com);
or:
LDAPUri LDAPUriTest = new LDAPUri("CN=Computers,DC=www,DC=codeproject,DC=com");

The above code returns the following:

  • LDAPUriTest.Port - 389
  • LDAPUriTest.Protocol - LDAPProtocol.LDAP
  • LDAPUriTest.LDAPPathShort - CN=Computers,DC=www,DC=codeproject,DC=com
  • LDAPUriTest.LDAPPath - LDAP://CN=Computers,DC=www,DC=codeproject,DC=com

Why?

When using the LDAPUri, the Path will be validated and will always be returned correctly.

History

  • 21st February, 2008: Initial post
  • 29th February, 2008: Article updated
    • Renamed the property Root to Host
    • Added Port property

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here