thanks Joe, I do some more searching and found another one of your posts
explaining this and it works for accessing the default context but when I
attempt to get the users name ('cn' property) it fails. the code is shown
below.
string currentUserName =
(((string)Context.User.Identity.Name).Split('\\'))[1];
string contextPath = "";
using(DirectoryEntry rootEntry = new
DirectoryEntry("LDAP://XXXXXX/RootDSE"))
{
contextPath = rootEntry.Properties["defaultNamingContext"].Value.ToString();
}
using(DirectoryEntry contextEntry = new DirectoryEntry("LDAP://" +
contextPath))
using(DirectorySearcher searcher = new DirectorySearcher())
{
searcher.SearchRoot = contextEntry;
searcher.Filter =
String.Format("(&(objectCategory=person)(samAccountName={0}))",
currentUserName);
searcher.PropertiesToLoad.Add("cn");
searcher.SearchScope = SearchScope.Subtree;
SearchResult result = searcher.FindOne();
return result.Properties["cn"][0].ToString();
}
When impersonation was used in asp.net then it all works perfectly fine as I
expected but using impersonation defeats what I am try to achieve.
"Joe Kaplan (MVP - ADSI)" <(E-Mail Removed)> wrote
in message news:#(E-Mail Removed)...
> The issue is probably serverless binding (not putting a server name in
your
> binding string). That only works if your current thread is running under
a
> domain account.
>
> Trying putting the DNS name of a domain controller in there
> (LDAP://server.com/RootDSE) and see if that fixes it. If so, that's your
> problem.
>
> http://support.microsoft.com/default...b;en-us;329986
>
> Joe K.
>
> "Ollie Riches" <(E-Mail Removed)> wrote in message
> news:eE0%(E-Mail Removed)...
> >I am trying to access an AD from asp.net, I am getting the 'famous' "The
> > specified domain either does not exist or could not be contacted"
> > exception
> > with a HR = 0x08007054b
> >
> > the code (C# .Net) is as follows:
> >
> > DirectoryEntry rootEntry = new DirectoryEntry("LDAP://RootDSE");
> > string contextPath =
> > rootEntry.Properties["defaultNamingContext"].Value.ToString();
> > rootEntry.Dispose();
> > DirectoryEntry contextEntry = new DirectoryEntry("LDAP://" +
contextPath);
> >
> > I know this code works and as far as I know I should be able to
> > access\query
> > the root but it fails. So is it a permissions issue with asp.net or the
> > domain configuration.
> >
> >
> > Cheers
> >
> > Ollie Riches
> > http://www.phoneanalyser.net
> >
> > Disclaimer: Opinions expressed in this forum are my own, and not
> > representative of my employer.
> > I do not answer questions on behalf of my employer. I'm just a
programmer
> > helping programmers.
> >
> >
>
>