M
M. Craig
Help!
Ultimately I'm trying to retrieve a list of users from active directory
using asp.net with C#. I have been able to do this using VBScript
successfully (with the ado object). With the C# code I receive error
message: System.Runtime.InteropServices.COMException: The specified domain
either does not exist or could not be contacted
Anyway, here is the VBScript that works:
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText =
"<LDAP://OU=Enterprise,dc=health,dc=ad>;;distinguishedName,name,mail"
Set ObjRecordSet = objCommand.Execute
While not objRecordset.EOF
if objRecordSet.Fields("mail") <> "" and
Left(objRecordSet.Fields("mail"),1) <> "!" then
wscript.echo objRecordSet.Fields("name") & vbTab & _
objRecordSet.Fields("mail")
end if
objRecordSet.MoveNext
Wend
And here is the Asp.Net code that doesn't.
if(!Page.IsPostBack)
{
DirectoryEntry de = new
DirectoryEntry("LDAP://OU=Enterprise,DC=HEALTH,DC=AD");
foreach(DirectoryEntry dEntry in de.Children)
{
Response.Write("<br>" + dEntry.Name.ToString());
}
}
Ultimately I'm trying to retrieve a list of users from active directory
using asp.net with C#. I have been able to do this using VBScript
successfully (with the ado object). With the C# code I receive error
message: System.Runtime.InteropServices.COMException: The specified domain
either does not exist or could not be contacted
Anyway, here is the VBScript that works:
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText =
"<LDAP://OU=Enterprise,dc=health,dc=ad>;;distinguishedName,name,mail"
Set ObjRecordSet = objCommand.Execute
While not objRecordset.EOF
if objRecordSet.Fields("mail") <> "" and
Left(objRecordSet.Fields("mail"),1) <> "!" then
wscript.echo objRecordSet.Fields("name") & vbTab & _
objRecordSet.Fields("mail")
end if
objRecordSet.MoveNext
Wend
And here is the Asp.Net code that doesn't.
if(!Page.IsPostBack)
{
DirectoryEntry de = new
DirectoryEntry("LDAP://OU=Enterprise,DC=HEALTH,DC=AD");
foreach(DirectoryEntry dEntry in de.Children)
{
Response.Write("<br>" + dEntry.Name.ToString());
}
}