M
msnews.microsoft.com
I have ADSI code that I can make work at the command line. I cannot in
any way get it to work in asp.net. Even using Windows authentication,
impersonation on, and providing the credentials hardcoded, I cannot make
this same code happen. This is all I am trying to do:
static void Stuff()
{
//we don't need the credentials on this form
// so store in session state.
//look up computers from selected branch.
DataTable dt = new DataTable("Computers");
dt.Columns.Add("ComputerName");
DirectoryEntry de = new
DirectoryEntry("LDAP://CN=Computers,DC=TOPDOMAIN,DC=CA");
de.Username = "adminishtypeaccount";
de.Password = "biglongpasswordofsomesort";
DirectorySearcher ds = new DirectorySearcher(de);
//try
{
foreach(SearchResult sr in ds.FindAll())
{
DataRow dr = dt.NewRow();
dr["ComputerName"] = sr.GetDirectoryEntry().Name.ToString();
dt.Rows.Add(dr);
}
}
//catch
{
//no action for now.
}
/* web version attaches
to a grid then binds
- only difference */
DataSet MySet = new DataSet();
MySet.Tables.Add(dt);
Console.WriteLine(MySet.GetXml());
Console.ReadLine();
}
}
any way get it to work in asp.net. Even using Windows authentication,
impersonation on, and providing the credentials hardcoded, I cannot make
this same code happen. This is all I am trying to do:
static void Stuff()
{
//we don't need the credentials on this form
// so store in session state.
//look up computers from selected branch.
DataTable dt = new DataTable("Computers");
dt.Columns.Add("ComputerName");
DirectoryEntry de = new
DirectoryEntry("LDAP://CN=Computers,DC=TOPDOMAIN,DC=CA");
de.Username = "adminishtypeaccount";
de.Password = "biglongpasswordofsomesort";
DirectorySearcher ds = new DirectorySearcher(de);
//try
{
foreach(SearchResult sr in ds.FindAll())
{
DataRow dr = dt.NewRow();
dr["ComputerName"] = sr.GetDirectoryEntry().Name.ToString();
dt.Rows.Add(dr);
}
}
//catch
{
//no action for now.
}
/* web version attaches
to a grid then binds
- only difference */
DataSet MySet = new DataSet();
MySet.Tables.Add(dt);
Console.WriteLine(MySet.GetXml());
Console.ReadLine();
}
}