Click here to Skip to main content
6,916,310 members and growing! (17,800 online)
Email Password   helpLost your password?
Languages » C# » General     Beginner License: The Code Project Open License (CPOL)

Lightweight Directory Access Protocol Uniform Resource Identifier (LDAPUri)

By Paw Jershauge

An Attempt to make Uniform resource identifier for the Lightweight Directory Access Protocol
C# (C#1.0, C#2.0, C#3.0), Dev
Posted:21 Feb 2008
Updated:28 Feb 2008
Views:10,823
Bookmarked:9 times
printPrint Friendly   add Share
      Discuss Discuss   Broken Article?Report  
2 votes for this article.
Popularity: 0.90 Rating: 3.00 out of 5
1 vote, 50.0%
1

2

3

4
1 vote, 50.0%
5
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Paw Jershauge


Member
ListView Group Sorter An Code Generator, for making SQL table into .Net Classses (2nd place in the Code Generation 2008 Competition)
A Class for getting the Rss feed list of a website Seagate Date Code Calculator DNSBL lookup Class Base N converter (N = 10-62) Lightweight Directory Access Protocol Uniform resource identifier (LDAPUri) LoginHours from DirectoryEntry into boolean array
Occupation: Software Developer
Location: Denmark Denmark

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+PgUp/PgDown to switch pages.

PermaLink | Privacy | Terms of Use
Last Updated: 28 Feb 2008
Editor: Deeksha Shenoy
Copyright 2008 by Paw Jershauge
Everything else Copyright © CodeProject, 1999-2010
Web09 | Advertise on the Code Project