By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,169 Members | 1,661 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,169 IT Pros & Developers. It's quick & easy.

Error during remote access to Active Directory

P: n/a
I'm trying to use Active Directory to get a list of users that are in the
same directory as the logon user. I'm trying to do this as a Web App written
in C# using Windows Security and Impersonation. When running from the local
host I have no problem; but when I try the same thing remotely I get the
error "System.Runtime.InteropServices.COMException" on the second hit on
Active Directory, the first hit works fine. I used to get the same error all
the time until I started using Impersonation.

Any suggestions as to what might be the issue?

Below is the specific code in question. It errors out at "DirectoryEntry
child"
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!IsPostBack)
{
DirectoryEntry user_entry = new
DirectoryEntry("LDAP://DOMAIN.org/DC=DOMAIN,DC=org");
DirectorySearcher mySearcher = new DirectorySearcher(user_entry);
Session["User.ID"] = User.Identity.Name.ToString().Substring(12);
mySearcher.Filter = ("(CN=" + Session["User.ID"].ToString() + ")");
SearchResult resEnt = mySearcher.FindOne();

Session["User.Name"] =
resEnt.GetDirectoryEntry().Properties["DisplayName"].Value.ToString();
Session["User.Path"] = resEnt.Path.ToString();
Session["User.CN"] =
resEnt.GetDirectoryEntry().Properties["CN"].Value.ToString();
lblWelcome.Text = "Welcome, " + Session["User.Name"].ToString();

string TempString = resEnt.Path.ToString().Replace("CN=" +
Session["User.CN"].ToString() + ",", "");
DirectoryEntry local_entry = new DirectoryEntry(TempString);
//this is where the error occurs
foreach(DirectoryEntry child in local_entry.Children)
{
if (child.Properties.Contains("Mail") == true)
{
string tempString1 = child.Properties["DisplayName"].Value.ToString();
string tempString2 = child.Properties["Mail"].Value.ToString();
ListItem tempItem = new ListItem(tempString1,tempString2);
ddlNominee.Items.Add(tempItem);
}
}
}
}
Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.