Hi,

This seems strange to me and was wondering if anyone had any insight as to
why this fails (for users not on the machine) when the ou is included in the
rootpath for the DirectorySearcher, but works for everyone if it isn't
included?

The code and explanation in commented sections
private void strange()
{
// userdn is actually fetched elsewhere in the program by a different ldap
query
string userdn = "cn=Last\\, First M.,ou=group,ou=site,ou=X,dc=X,dc=Y,dc=Z";

// this is the rootpath for the active directory query
string rootpath = null;
// works if I am on the machine hosting the web app, but fails if I'm not
rootpath = "LDAP://server/ou=X,dc=X,dc=Y,dc=com";
// this rootpath always works (the "ou=X" has been removed)
rootpath = "LDAP://server/dc=X,dc=Y,dc=com";

string [] props = new string[2];
props[0] = "cn";
props[1] = "objectGUID";

DirectoryEntry adroot = new DirectoryEntry(rootpath);
DirectorySearcher dsrch = new DirectorySearcher(adroot,
"(&(objectClass=user)(manager="+userdn+"))",props) ;
// the error occurs on the below line if the first rootpath is used
SearchResultCollection srcoll= dsrch.FindAll();
}

The stacktrace from the error follows:
Server Error in '/StrangeApp' Application.
--------------------------------------------------------------------------------

The specified directory service attribute or value does not exist
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: The
specified directory service attribute or value does not exist

Source Error:

Line 49: DirectoryEntry adroot = new DirectoryEntry(rootpath);
Line 50: DirectorySearcher dsrch = new DirectorySearcher(adroot,
"(&(objectClass=user)(manager="+userdn+"))",props) ;
Line 51: SearchResultCollection srcoll= dsrch.FindAll();
Line 52: }
Line 53:

Source File: c:\inetpub\wwwroot\StrangeApp\StrangeClass.aspx.cs Line: 51

Stack Trace:
[COMException (0x8007200a): The specified directory service attribute or
value does not exist]
System.DirectoryServices.DirectoryEntry.Bind(Boole an throwIfFail) +513
System.DirectoryServices.DirectoryEntry.Bind() +10
System.DirectoryServices.DirectoryEntry.get_AdsObj ect() +10
System.DirectoryServices.DirectorySearcher.FindAll (Boolean
findMoreThanOne) +198
System.DirectoryServices.DirectorySearcher.FindAll () +10
StrangeApp.StrangeClass.strange() in
c:\inetpub\wwwroot\StrangeApp\StrangeClass.aspx.cs :51
StrangeApp.StrangeClass.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\StrangeApp\StrangeClass.aspx.cs :171
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET
Version:1.1.4322.573


Thanks,

Todd Thompson