views:

2220

answers:

5

Hi,

I am trying to connect to an edirectory 8.8 server running LDAP. How would I go about doing that in .Net? Can I still use the classes in System.DirectoryService such as DirectoryEntry and DirectorySearcher or are they AD specific? Do I need to specify the "Connection String" any differently?

I am trying something like the code below but it doesn't seem to work...

DirectoryEntry de = new DirectoryEntry ("LDAP://novellBox.sample.com","admin","password",AuthenticationTypes.None);
DirectorySearcher ds = new DirectorySearcher(de);
var test = ds.FindAll();

Any ideas?

A: 

I think you need to use LDAP syntax for the host.

Make sure you don't forget to release the connection with using - if you don't dispose of the directory entries they hang around forever until the pool runs out and your app breaks.

using (DirectoryEntry de = new DirectoryEntry ("LDAP://CN=server,DC=domain,DC=com","admin","password",AuthenticationTypes.Secure))
{
    ...
}
wefwfwefwe
A: 

I had a hard time figuring this out but you could use something like the following, it worked sweet for me:

Domain domain = Domain.GetDomain(new DirectoryContext(DirectoryContextType.Domain, "novellBox.sample.com");
DirectorySearcher ds = new DirectorySearcher(domain.GetDirectoryEntry(), searchQuery);
using (SearchResultCollection src = ds.FindAll())
{....}
Fermin
Hi Fermin, is this connecting to edirectory or AD? the "Domain" object seems to live in the ActiveDirectory namespace. Still trying to get it to work though.
Chaitanya
A: 

Well, I think your connection string is missing a bit - specifying just the server name isn't good enough - you also need to specify a "starting point" for your search.

In AD, this would typically be something like the "Users" container in your domain, which you'd specify like this in LDAP parlance:

LDAP://novellBox.sample.com/cn=Users,dc=YourCompany,dc=com

Not sure how LDAP compliant the newer versions of eDirectory are - but that should work since in theory, it's standard LDAP regardless of the implementation :-)

But then again: only in theory, there's no difference between theory and practice.....

There's also a System.DirectoryServices.Protocols namespace which offers low-level LDAP calls directly - and that's definitely not tied to AD at all, but it's really quite low-level.....

There's also a Novell C# LDAP library but I've never tried it and can't say how complete or capable it is. It might give you some clues, though!

Also see this other Stackoverflow question about Novell, LDAP and C# - it might give you additional info.

Marc

marc_s
Hi Marc, no go with this either. eDirectory doesn't seem to like it. The SEs reckon the DC in the connection string is very AD specific. I had already seen the other question, but was trying to stay closer to the general MS implementation rather than take a dependency on yet another implementation.
Chaitanya
eDir syntax is rarely ending in dc=this,dc=that. More typically it would be ou=OrgU,o=Org instead of the dc= notation.Obviously you have to have the correct specific DN for the search base...
geoffc
A: 

I am trying to connect to an edirectory 8.8 server running LDAP. How would I go about doing that in .Net? Can I still use the classes in System.DirectoryService such as DirectoryEntry and DirectorySearcher or are they AD specific?

We are using System.DirectoryServices for Microsoft Active Directory, OpenLDAP running on Linux and eDirectiry without any problem. So the answer is yes, you can use these classes to access eDir.

Do I need to specify the "Connection String" any differently?

Yes you are. When passing to DirectoryEntry a string starting with "LDAP://" you need to conform to the LDAP syntax which is very different than URI syntax.

I recommend you to use an LDAP browser (google it, there are many free downloads) in order to get the correct path to the root object otherwise you will spend time on trying to figure out the correct object types.

Hope this helps

Joshua
A: 

Source Code DirectoryEntry de = new DirectoryEntry("LDAP://shafqaa-vpc1:636/ou=Novell,o=Novelled", "cn=admin,o=Novelled", "123", AuthenticationTypes.ServerBind);

DirectorySearcher ds = new DirectorySearcher(de, "(objectClass=user)"); SearchResultCollection results = ds.FindAll();

Hi i got this error The server is not operational.

Stack Trace " at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)\r\n at System.DirectoryServices.DirectoryEntry.Bind()\r\n at System.DirectoryServices.DirectoryEntry.get_AdsObject()\r\n at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)\r\n at System.DirectoryServices.DirectorySearcher.FindAll()\r\n at NovellTest.Form1.Form1_Load(Object sender, EventArgs e) in C:\Documents and Settings\Administrator.CORDELIA\My Documents\Visual Studio 2008\Projects\NovellTest\NovellTest\Form1.cs:line 43\r\n at System.Windows.Forms.Form.OnLoad(EventArgs e)\r\n at System.Windows.Forms.Form.OnCreateControl()\r\n at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)\r\n at System.Windows.Forms.Control.CreateControl()\r\n at System.Windows.Forms.Control.WmShowWindow(Message& m)\r\n at System.Windows.Forms.Control.WndProc(Message& m)\r\n at System.Windows.Forms.ScrollableControl.WndProc(Message& m)\r\n at System.Windows.Forms.ContainerControl.WndProc(Message& m)\r\n at System.Windows.Forms.Form.WmShowWindow(Message& m)\r\n at System.Windows.Forms.Form.WndProc(Message& m)\r\n at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)\r\n at System.Windows.Forms.Control.SetVisibleCore(Boolean value)\r\n at System.Windows.Forms.Form.SetVisibleCore(Boolean value)\r\n at System.Windows.Forms.Control.set_Visible(Boolean value)\r\n at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.Run(Form mainForm)\r\n at NovellTest.Program.Main() in C:\Documents and Settings\Administrator.CORDELIA\My Documents\Visual Studio 2008\Projects\NovellTest\NovellTest\Program.cs:line 18\r\n at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)\r\n at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.ThreadHelper.ThreadStart()"

Please helpt me

ahsan shafqat