Active Directory, LDAP and Forms Authentication Problem

K

Ken Dourado

Hi,

I've got an intranet ASP.NET application that uses Forms Authentication.
What I'd like to do is get the username (in the format name.surname) of
the visitor and then retrieve their Display Name from Active Directory
using the following method:

internal static string GetUserDisplayName(string id)
{
string html = "";
DirectoryEntry objDomain = new DirectoryEntry("LDAP://DOMAINNAME");
DirectorySearcher objSearcher = new DirectorySearcher(objDomain);
objSearcher.Filter = ("(objectClass=user)(sn=" + id ")");
foreach(SearchResult sr in objSearcher.FindAll()) // this line errors
{
DirectoryEntry de = sr.GetDirectoryEntry();
html = de.Properties["DisplayName"].Value.ToString() + "<br>";
}
return html;
}

I keep getting the following error message:
System.Runtime.InteropServices.COMException: The directory service is
unavailable

I'm a newbie at this so I don't really understand where I'm going wrong
or if I have to set anything up before carrying on.

Thanks in advance for any help.

Regards,

Ken.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top